Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import flash.display.MovieClip;
- import flash.events.KeyboardEvent;
- import flash.ui.Keyboard;
- import flash.events.Event;
- public class Main extends MovieClip
- {
- var vx:int;
- public function Main()
- {
- init();
- }
- function init():void
- {
- vx = 0;
- //Add event listeners
- stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
- stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
- addEventListener(Event.ENTER_FRAME, onEnterFrame);
- }
- function onKeyDown(event:KeyboardEvent):void
- {
- if (event.keyCode == Keyboard.RIGHT)
- {
- vx = 5;
- }
- else if (event.keyCode == Keyboard.LEFT)
- {
- vx = -5;
- }
- }
- function onKeyUp(event:KeyboardEvent):void
- {
- if (event.keyCode == Keyboard.LEFT || event.keyCode == Keyboard.RIGHT)
- {
- vx = 0;
- }
- function onEnterFrame(event:Event):void
- {
- //Move the player
- player.x += xv;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment