Moving a Movie Clip


1) Open Macromedia Flash-- If you do not have, google Macromedia Flash.
2) Start a new flash document

Here we go!

Clck F9 to open the actions panel.

Type in
Flash ActionScript
  1. stop();

Or Esc + S + T (Short cut)

Now, click F9 again to close the actions panel, and draw a circle with a mouth and eye.

Now, press CTRL A and then F8 and make it a Movie Clip.

Now, select your movie clip and click properties and set the instance as "man" , now, press F9 again to open the actions panel for the movie clip and enter the folloing code:
Flash ActionScript
  1. onClipEvent(enterFrame){
  2.  
  3. if(Key.isDown(Key.RIGHT)){
  4. this._x += 5;
  5. this._xscale = 100;
  6. }
  7.  
  8. if(Key.isDown(Key.LEFT)){
  9. this._x -= 5;
  10. this._xscale = -100;
  11. }
  12.  
  13. if(Key.isDown(Key.UP)){
  14. this._y -= 5;
  15. }
  16.  
  17. if(Key.isDown(Key.DOWN)){
  18. this._y += 5;
  19. }
  20. }


To make it move smoother,
Click anywhere on the grey area, press F9 to open the properties and set the Frame rate to about 30 fps ;)

Here`s a explanation of the codes:

Flash ActionScript
  1. onClipEvent(enterFrame){

This means that everything between { and } runs every time it goes to a new frame.
Flash ActionScript
  1. if(Key.isDown(Key.RIGHT)){
  2. this._x += 5;

If the Right key is down, the movieclip will move +5 X.
Joshua's Avatar
Author:
Views:
2,271
Rating:
There are currently no comments for this tutorial, login or register to leave one.