Would you like to react to this message? Create an account in a few clicks or log in to continue.

Actionscript [Moving Movie Clips using Keyboard]

Go down

Actionscript [Moving Movie Clips using Keyboard] Empty Actionscript [Moving Movie Clips using Keyboard]

Post by Wingedge Tue Oct 14, 2008 2:23 am

To capture Keyboard input, Actionscript uses the object "Key". This object listens to Keyboard events such as keydown, keyup, keypress and also returns keycode being pressed.



[putting the script on stage and movie clip's instance name is MC]
Code:

MC.onEnterFrame = function(){
  if (Key.isDown(Key.UP)){
    MC._y-=1;  // moves MC 1 pixel upward... y-axis
  }
}

[putting the script on the movie clip itself ]
Code:

onClipEvent(keyDown){ // keyDown event triggers when a key is pressed
  if(Key.isDown(Key.UP)){
    this._y-=1;// moves this movie clip 1 pixel upward... y-axis
  }
}
Wingedge
Wingedge
Admin
Admin

Male
Number of posts : 77
Age : 40
Name : Sir Francis
Year Level : Instructor
Location : UC
Registration date : 2008-06-10

Credits
GP: 9999

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum