Here is a quick tut on how to make a movieclip movable using the arrow keys.
First we are gonna need to import some events:
Now lets declare a variable for speed:
Now a few variables which will tell us whether or not each button is pressed:
now we are going to add an event listener that listens for any key being pressed, one that checks for keys released and one for enter frame:
Now you need to create the movie clip that we are going to make move. It can be any shape or size. Give it the instance name object_mc . Now lets see the key down function. Type this:
This basically makes it so that when one of the variables is true, that button was pressed.
Now for the key up function :
This makes it so that when the key is released, the variable returns to false. Without this, after pressing the button once, the movieclip would keep moving in that direction even after the key was released. Now make a movieclip. It can be any size or shape. Just give it the instance name "object_mc" without the quotes. Now for the enter frame function:
This actually moves the movieclip while the key is held. You can make it move faster or slower by changing the speed variable. So, as you can see arrow key movement is pretty easy with AS3. Any questions, email me or post.
[ Upcoming Event] Mobile Security Summit 2016 – South Africa - Rhys Mossom will be providing an indepth, out of the box look at what mobile security means and the importance of well-organized collaboration. The two day...
2 years ago