Quantunet.com

My Account

Joins Us
Flash 8 Actionscript 2.0 Knowledgebase
Using The Arrow Keys  

Download .fla

How to create following effect.


Actionscript

ball_mc.onEnterFrame = function (){
if(Key.isDown(Key.UP)){
this._y -= 5;
}
if(Key.isDown(Key.DOWN)){
this._y += 5;
}
if(Key.isDown(Key.RIGHT)){
this._x += 5;
}
if(Key.isDown(Key.LEFT)){
this._x -= 5;
}
};


How The Actionscript Works

Note: The advantage of using this method is that you can hold down multiple keys to create a combined effect. e.g If you hold down the right arrow key and the up arrow key the ball will move diagonaly to the top right of the stage.

However one of the main draw backs is that this method relies on flash checking four conditions everytime it enters a new frame. To make this process more efficient it would be better to use a key listener that sends a signal each time a key is pressed. To learn more see [Using all the arrow keys III (listener method)].


© 2008 Quantunet LLC All Rights Reserved | Intellectual Property | Terms of Use | Privacy
Home | About Quantunet | FAQ's | Contact Us