pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

ActionScript pastebin - collaborative debugging tool View Help


Posted by sheel on Fri 9 Oct 20:38
report abuse | View followups from - | download | new post

  1. package
  2. { // start package
  3.        
  4.         import flash.display.MovieClip;
  5.         import flash.events.*;
  6.        
  7.         public class Main extends MovieClip
  8.         { // start public class Main
  9.                 var speed:Number = 5;
  10.                
  11.                 var handChar:HandChar = new HandChar(); // define MovieClip "handChar"
  12.                
  13.                 var leftKeyDown:Boolean = false; // move left
  14.                 var upKeyDown:Boolean = false; // jump
  15.                 var rightKeyDown:Boolean = false; // move right
  16.                 var downKeyDown:Boolean = false; // disabled
  17.                
  18.                 var hKeyDown:Boolean = false; // scissor attack
  19.                 var jKeyDown:Boolean = false; // paper attack
  20.                 var kKeyDown:Boolean = false; // rock attack
  21.                
  22.                 var mainJumping:Boolean = false;
  23.                 var jumpSpeedLimit:int = 15;
  24.                 var jumpSpeed:Number = jumpSpeedLimit;
  25.                
  26.                 public function Main()
  27.                 { // start public function Main (constructor)
  28.                         addEventListener(Event.ENTER_FRAME, moveHand);
  29.                         addEventListener(Event.ENTER_FRAME, boundaries);
  30.                         stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
  31.                         stage.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);
  32.                         handChar.handCharobject.addEventListener (Event.ENTER_FRAME, endKeyDown);
  33.                        
  34.                         createHand();
  35.                         } // end public function Main (constructor)
  36.                
  37.                 private function createHand():void
  38.                 { // start private function createHand
  39.                         handChar.x = 200;
  40.                         handChar.y = 145;
  41.                         handChar.scaleX = 1;
  42.                         handChar.scaleX = 1;
  43.                         addChild(handChar);
  44.                 } // end private function createHand
  45.                
  46.                 private function endKeyDown (event:Event):void
  47.                 {
  48.                         if(handChar.handCharobject.currentLabel == "endofclip")
  49.                         {
  50.                                 hKeyDown = false;
  51.                                 stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
  52.                         }
  53.                         if(handChar.handCharobject.currentLabel == "endofclip")
  54.                         {
  55.                                 jKeyDown = false;
  56.                                 stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
  57.                         }
  58.                         if(handChar.handCharobject.currentLabel == "endofclip")
  59.                         {
  60.                                 kKeyDown = false;
  61.                                 stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
  62.                         }
  63.                 }
  64.                
  65.                 private function checkKeysDown (event:KeyboardEvent):void
  66.                 { // start private function checkKeysDown
  67.                         if(event.keyCode == 37 || event.keyCode == 65)
  68.                         {
  69.                                 leftKeyDown = true;
  70.                         }
  71.                         if(event.keyCode == 38 || event.keyCode == 87)
  72.                         {
  73.                                 upKeyDown = true;
  74.                         }
  75.                         if(event.keyCode == 39 || event.keyCode == 68)
  76.                         {
  77.                                 rightKeyDown = true;
  78.                         }
  79.                         if(event.keyCode == 40 || event.keyCode == 83)
  80.                         {
  81.                                 downKeyDown = true;
  82.                         }
  83.                         if(event.keyCode == 72)
  84.                         {
  85.                                 hKeyDown = true;
  86.                                 stage.removeEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
  87.                         }
  88.                         if(event.keyCode == 74)
  89.                         {
  90.                                 jKeyDown = true;
  91.                                 stage.removeEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
  92.                         }
  93.                         if(event.keyCode == 75)
  94.                         {
  95.                                 kKeyDown = true;
  96.                                 stage.removeEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
  97.                         }
  98.                 } // end private function checkKeysDown
  99.                
  100.                 private function checkKeysUp (event:KeyboardEvent):void
  101.                 { // start private function checkKeysUp
  102.                         if(event.keyCode == 37 || event.keyCode == 65)
  103.                         {
  104.                                 leftKeyDown = false;
  105.                         }
  106.                         if(event.keyCode == 38 || event.keyCode == 87)
  107.                         {
  108.                                 upKeyDown = false;
  109.                         }
  110.                         if(event.keyCode == 39 || event.keyCode == 68)
  111.                         {
  112.                                 rightKeyDown = false;
  113.                         }
  114.                         if(event.keyCode == 40 || event.keyCode == 83)
  115.                         {
  116.                                 downKeyDown = false;
  117.                         }
  118.                 } // end private function checkKeysUp
  119.                        
  120.                 private function moveHand (e:Event) : void
  121.                 { // start private function moveHand
  122.                         if(leftKeyDown)
  123.                         {
  124.                                 if(upKeyDown || mainJumping)
  125.                                 {
  126.                                         handChar.x -=speed;
  127.                                         handChar.scaleX = -1;
  128.                                         handChar.gotoAndPlay(5);
  129.                                         mainJump();
  130.                                         return;
  131.                                 }
  132.                                 handChar.x -= speed;
  133.                                 handChar.scaleX = -1;
  134.                                 handChar.gotoAndPlay(1);
  135.                                 return;
  136.                         }
  137.                        
  138.                         if(rightKeyDown)
  139.                         {
  140.                                 if(upKeyDown || mainJumping)
  141.                                 {
  142.                                         handChar.x +=speed;
  143.                                         handChar.scaleX = 1;
  144.                                         handChar.gotoAndPlay(5);
  145.                                         mainJump();
  146.                                         return;
  147.                                 }
  148.                                 handChar.x += speed;
  149.                                 handChar.scaleX = 1;
  150.                                 handChar.gotoAndPlay(1);
  151.                                 return;
  152.                         }
  153.                        
  154.                         if(upKeyDown || mainJumping)
  155.                         {
  156.                                 handChar.gotoAndPlay(5);
  157.                                 mainJump();
  158.                                 return;
  159.                         }
  160.                        
  161.                         if(hKeyDown)
  162.                         {
  163.                                 handChar.gotoAndStop("scissor");
  164.                                 return;
  165.                         }
  166.                        
  167.                         if(jKeyDown)
  168.                         {
  169.                                 handChar.gotoAndStop("paper");
  170.                                 return;
  171.                         }
  172.                        
  173.                         if(kKeyDown)
  174.                         {
  175.                                 handChar.gotoAndStop("rock");
  176.                                 return;
  177.                         }
  178.                        
  179.                         handChar.gotoAndPlay(3);
  180.                 } // end private function Movehand
  181.                
  182.                 private function boundaries (e:Event):void
  183.                  { // start private function boundaries
  184.                          if(handChar.x > stage.stageWidth - handChar.width/2)
  185.                          {
  186.                                  handChar.x = stage.stageWidth - handChar.width/2;
  187.                          }
  188.                          if(handChar.x < 15)
  189.                          {
  190.                                  handChar.x = 15;
  191.                          }
  192.          } // end private function boundaries
  193.                        
  194.                
  195.                 private function mainJump():void
  196.                 { // start private function mainJump
  197.                         if(!mainJumping)
  198.                         {
  199.                                 mainJumping = true;
  200.                                 jumpSpeed = jumpSpeedLimit*-1;
  201.                                 handChar.y += jumpSpeed;
  202.                         }
  203.                         else
  204.                         {
  205.                         if(jumpSpeed < 0)
  206.                         {
  207.                                 jumpSpeed *= 1 - jumpSpeedLimit/75;
  208.                         if(jumpSpeed > -jumpSpeedLimit/5)
  209.                                 {
  210.                                         jumpSpeed *= -1;
  211.                                 }
  212.                         }
  213.                         if(jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit)
  214.                                 {
  215.                                         jumpSpeed *= 1 + jumpSpeedLimit/50;
  216.                                 }
  217.                         handChar.y += jumpSpeed;
  218.                        
  219.                         if(handChar.y >= stage.stageHeight - handChar.height)
  220.                                 {
  221.                                 mainJumping = false;
  222.                                 handChar.y = stage.stageHeight - handChar.height;
  223.                                 }
  224.                         }
  225.                 } // end private function mainJump
  226.                 } // end public class Main
  227. } // end package

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post