Actionscript [Moving Movie Clips using Keyboard]

Go down

Actionscript [Moving Movie Clips using Keyboard]

Post by Wingedge on 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
  }
}
avatar
Wingedge
Admin
Admin

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

Credits
GP: 9999

View user profile

Back to top Go down

Back to top

- Similar topics

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