Guest User

Untitled

a guest
Apr 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3.     import flash.display.MovieClip;
  4.     import flash.events.KeyboardEvent;
  5.     import flash.ui.Keyboard;
  6.     import flash.events.Event;
  7.  
  8.     public class Main extends MovieClip
  9.     {
  10.         var vx:int;
  11.  
  12.         public function Main()
  13.         {
  14.             init();
  15.         }
  16.         function init():void
  17.         {
  18.             vx = 0;
  19.  
  20.             //Add event listeners
  21.             stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
  22.             stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
  23.             addEventListener(Event.ENTER_FRAME, onEnterFrame);
  24.         }
  25.         function onKeyDown(event:KeyboardEvent):void
  26.         {
  27.             if (event.keyCode == Keyboard.RIGHT)
  28.             {
  29.                 vx = 5;
  30.             }
  31.             else if (event.keyCode == Keyboard.LEFT)
  32.             {
  33.                 vx = -5;
  34.             }
  35.         }
  36.         function onKeyUp(event:KeyboardEvent):void
  37.         {
  38.             if (event.keyCode == Keyboard.LEFT || event.keyCode == Keyboard.RIGHT)
  39.             {
  40.                 vx = 0;
  41.             }
  42.             function onEnterFrame(event:Event):void
  43.             {
  44.                 //Move the player
  45.                 player.x +=  xv;
  46.             }
  47.         }
  48.     }
  49. }
Add Comment
Please, Sign In to add comment