How to move a movie clip with the Arrow keys
In this short tutorial i will explain how to move a movie clip with your arrow keys,
To start you should have the movie clip that you want to be able to control with the arrow keys ready,
We are now going to add the Actionscript to the movie clip, we need to select the movie clip and display the
Actionscript panel you can do this by either pressing F9 or by going to window>actions,
now copy and paste the following code in to it:
onClipEvent(enterFrame){
if(Key.isDown(Key.RIGHT)){
this._x += 5;
}
if(Key.isDown(Key.LEFT)){
this._x -= 5;
}
if(Key.isDown(Key.UP)){
this._y -= 5;
}
if(Key.isDown(Key.DOWN)){
this._y += 5;
}
}
Code look confusing? don't worry about it, its pretty easy to understand heres a breakdown of what the code does.
onClipEvent(enterFrame){
This basically means that when this movieclip is present in the current frame do what is says in the brackets,
if(Key.isDown(Key.LEFT)){
This basically means if that key is down do what it says in the brackets,
this._x -= 5;
This means that the X coordinates are increased by 5,
this._y += 5;
This means that the Y coordinates are increased by 5,
See simple wasnt it? you should now have something similar to this: