Fire Weapons with Key.addListener
Summary
Wow... this one was a monster that should have been divided into to separate lessons! Well, we ended up with a cool project, and we're on our way to making a full-fledged game!
Important Concepts
var keyListener:Object = new Object();
keyListener.onKeyUp = function() {
if(Key.getCode()==Key.SPACE){
fire();
}
};
Key.addListener(keyListener);
Self-Challenge for Understanding
Create a project that increments a variable when you hold the space bar down (use an onEnterFrame function) Return the variable to zero when the space bar is released. You'll need to use the keyListener script above: