Mars714

Data Battle character movement

Feb 18th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Move with Keyboard Arrows
  2. Allows the specified symbol instance to be moved with the keyboard arrows.
  3.  
  4. Instructions:
  5. 1. To increase or decrease the amount of movement, replace the number 5 below with the number of pixels you want the symbol instance to move with each key press.
  6. Note the number 5 appears four times in the code below.
  7. */
  8.  
  9. var upPressed:Boolean = false;
  10. var downPressed:Boolean = false;
  11. var leftPressed:Boolean = false;
  12. var rightPressed:Boolean = false;
  13. var MCMspeed:Number = 5;
  14.  
  15. MCM.addEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey_4);
  16. stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed_4);
  17. stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed_4);
  18.  
  19. function fl_MoveInDirectionOfKey_4(event:Event)
  20. {
  21.     if (upPressed)
  22.     {
  23.         MCM.y -=  5;
  24.         MCM.gotoAndPlay(17);
  25.         MCM.y -=  MCMspeed;
  26.     }
  27.     if (downPressed)
  28.     {
  29.         MCM.y +=  5;
  30.         MCM.gotoAndPlay(17);
  31.         MCM.y +=  MCMspeed;
  32.     }
  33.     if (leftPressed)
  34.     {
  35.         MCM.x -=  5;
  36.         MCM.gotoAndPlay(41);
  37.         MCM.x -=  MCMspeed;
  38.     }
  39.     if (rightPressed)
  40.     {
  41.         MCM.x +=  5;
  42.         MCM.gotoAndPlay(17);
  43.         MCM.x +=  MCMspeed;
  44.     }
  45. }
  46.  
  47. function fl_SetKeyPressed_4(event:KeyboardEvent):void
  48. {
  49.     switch (event.keyCode)
  50.     {
  51.         case Keyboard.UP :
  52.             {
  53.                 upPressed = true;
  54.                 break;
  55.  
  56.             };
  57.         case Keyboard.DOWN :
  58.             {
  59.                 downPressed = true;
  60.                 break;
  61.  
  62.             };
  63.         case Keyboard.LEFT :
  64.             {
  65.                 leftPressed = true;
  66.                 break;
  67.  
  68.             };
  69.         case Keyboard.RIGHT :
  70.             {
  71.                 rightPressed = true;
  72.                 break;
  73.  
  74.         }
  75.     }
  76. };
  77.  
  78. function fl_UnsetKeyPressed_4(event:KeyboardEvent):void
  79. {
  80.     switch (event.keyCode)
  81.     {
  82.         case Keyboard.UP :
  83.             {
  84.                 upPressed = false;
  85.                 break;
  86.  
  87.             };
  88.         case Keyboard.DOWN :
  89.             {
  90.                 downPressed = false;
  91.                 break;
  92.  
  93.             };
  94.         case Keyboard.LEFT :
  95.             {
  96.                 leftPressed = false;
  97.                 break;
  98.  
  99.             };
  100.         case Keyboard.RIGHT :
  101.             {
  102.                 rightPressed = false;
  103.                 break;
  104.  
  105.         }
  106.     }
  107. };
  108.  
  109.  
  110.  
  111. /* Click to Go to Frame and Play
  112. Clicking on the specified symbol instance moves the playhead to the specified frame in the timeline and continues playback from that frame.
  113. Can be used on the main timeline or on movie clip timelines.
  114.  
  115. Instructions:
  116. 1. Replace the number 5 in the code below with the frame number you would like the playhead to move to when the symbol instance is clicked.
  117. */
  118.  
  119. A.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_8);
  120.  
  121. function fl_ClickToGoToAndPlayFromFrame_8(event:MouseEvent):void
  122. {
  123.     MCM.gotoAndPlay(2);
  124.     if (MCM.Animator.frame(52))
  125.     MCM.gotoAndPlay(61);
  126.        
  127. }
  128.  
  129. /* Click to Go to Frame and Play
  130. Clicking on the specified symbol instance moves the playhead to the specified frame in the timeline and continues playback from that frame.
  131. Can be used on the main timeline or on movie clip timelines.
  132.  
  133. Instructions:
  134. 1. Replace the number 5 in the code below with the frame number you would like the playhead to move to when the symbol instance is clicked.
  135. */
  136.  
  137. B.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_9);
  138.  
  139. function fl_ClickToGoToAndPlayFromFrame_9(event:MouseEvent):void
  140. {
  141.     MCM.gotoAndPlay(9);
  142.     if (MCM.Animator.frame(52))
  143.     MCM.gotoAndPlay(53)
  144. }
Advertisement
Add Comment
Please, Sign In to add comment