title: Making my character fight
body: <p>I'm trying to create a beat em up game and right now i got my character walking and jumping. I have 3 attack animation so far and works just about. This is what i'm trying to achieve, if the player presses the attack button then the character will attack and if the player keeps pressing the attack button it will continue with its attack/punching sequence or if a different attack key is pressed it will switch attack/kicking animation (Note: I do no want if the player holds down the key, has to be a key press).</p>
  
  <p>Also how can i make it go to the next attack animation once the current attack animation has completely finished instead of jumping to the next frame midway of it's current attack animation. So while the character is attacking and the attack key is pressed the character will finish its current attack animation and as soon as it ends it moves on to the next attack animation frame otherwise it will stop. I'm not sure how i can do this, should i create arrays or extend classes. I want to create the game like this a copy i found but its in AS2 </p>
  
  <p><a href="https://www.dropbox.com/s/zhf68zmi0ktmeqq/DD%20%282%29.zip" rel="nofollow">https://www.dropbox.com/s/zhf68zmi0ktmeqq/DD%20%282%29.zip</a></p>
  
  <p>This is what i have done so far</p>
  
  <pre><code>package 
  {
      import flash.display.MovieClip;
      import flash.events.Event;
      import flash.events.KeyboardEvent;
      import flash.ui.Keyboard;
      import flash.utils.*;
      import com.greensock.TweenLite;
      import com.greensock.easing.*;
      import com.greensock.plugins.*;
  
      public class Player extends MovieClip
      {
          TweenPlugin.activate([BlurFilterPlugin]);
          //Player run speed setting;
          var RunSpeed:Number = 8;
          //Player key presses
          var RightKeyPress:Boolean = false;
          var LeftKeyPress:Boolean = false;
          var UpKeyPress:Boolean = false;
          //Jump variables
          var Gravity:Number = 1.5;
          var JumpPower:Number = 0;
          var CanJump:Boolean = false;
          var Jumped:Boolean = false;
          //Dash variable
          var Pressed:Boolean = false;
          var LastKeyPressed:Number = -1;
          var DashAmount:Number = 250;
          var DoubleTapDelay:Number = 260;//-- delay in milliseconds
          var Dashing:Boolean = false;
          var RightDash:Boolean = false;
          var LeftDash:Boolean = false;
  
          public function Player()
          {
              stage.addEventListener(KeyboardEvent.KEY_DOWN,KeyDown);
              stage.addEventListener(KeyboardEvent.KEY_DOWN,KeyPressed);
              addEventListener(Event.ENTER_FRAME,Update);
          }
  
          function KeyDown(event:KeyboardEvent)
          {
              stage.removeEventListener(KeyboardEvent.KEY_DOWN, SecondDash);
              //If key is down cannot dash
              RightDash = false;
              LeftDash = false;
  
              //When Key is Down
              if (event.keyCode == 39)
              {
                  RightKeyPress = true;
              }
  
              if (event.keyCode == 37)
              {
                  LeftKeyPress = true;
              }
  
              if (event.keyCode == 38)
              {
                  UpKeyPress = true;
              }
          }
  
          function KeyPressed(event:KeyboardEvent):void
          {
              stage.removeEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
              stage.addEventListener(KeyboardEvent.KEY_UP, KeyUp);
  
              //If on floor
              if (CanJump)
              {
                  //If right key is down
                  if (event.keyCode == 39)
                  {
                      if (event.keyCode == 39 &amp;&amp; Pressed)
                      {
                          //If right key press matches with recent right key press, dash right
                          Dashing = true;
                          RightDash = true;
                      }
                      Pressed = true;
                      setTimeout(function(){Pressed = false}, DoubleTapDelay);
                  }
  
                  if (event.keyCode == 37)
                  {
                      if (event.keyCode == 37 &amp;&amp; Pressed)
                      {
                          //If left key press matches with recent left key press, dash left
                          Dashing = true;
                          LeftDash = true;
                      }
                      Pressed = true;
                      setTimeout(function(){Pressed = false}, DoubleTapDelay);
                  }
  
              }
          }
  
  
  
          function Update(event:Event)
          {
  
              //Adding gravity to the game world
              JumpPower +=  Gravity;
              //if player is more than 300 on the y-axis
              if (this.y &gt; 300)
              {
                  //Player stays on the ground and can jump
                  JumpPower = 0;
                  CanJump = true;
              }
  
  
                  //If already jumped and on floor
                  if (Jumped == true &amp;&amp; CanJump)
                  {
                      //Cannot jump again
                      CanJump = false;
  
                      //If on floor and right key is pressed run right
                      if ((RightKeyPress))
                      {
                          gotoAndStop('Run');
                          scaleX = 1;
                      }
                      else if ((LeftKeyPress))
                      {
                          //Otherwise if on floor and left key is pressed run left
                          gotoAndStop('Run');
                          scaleX = -1;
                      }
  
                      //If no key is pressed stay idle
                      if ((!RightKeyPress &amp;&amp; !LeftKeyPress))
                      {
                          gotoAndStop('Idle');
                      }
                  }
  
  
                  //If on floor and can jump
                  if (CanJump)
                  {
                      //If right key is pressed run right
                      if ((RightKeyPress))
                      {
                          x +=  RunSpeed;
                          gotoAndStop('Run');
                          scaleX = 1;
                      }
                      else if ((LeftKeyPress))
                      {
                          //otherwise if left key is pressed run left
                          x -=  RunSpeed;
                          gotoAndStop('Run');
                          scaleX = -1;
                      }
  
                      if ((UpKeyPress))
                      {
                          //If up key is pressed then jump
                          JumpPower = -15;
                          CanJump = false;
                          gotoAndStop('Jump');
                          Jumped = true;
                      }
  
                      //If no key is pressed stay idle
                      if ((!RightKeyPress &amp;&amp; !LeftKeyPress &amp;&amp; CanJump))
                      {
                          gotoAndStop('Idle');
                      }
                  }
                  else if (CanJump == false)
                  {
                      //Otherwise if in air and right key is pressed move right
                      if ((RightKeyPress))
                      {
                          x +=  RunSpeed;
                          scaleX = 1;
                      }
                      else if ((LeftKeyPress))
                      {
                          //Otherwise if left key is pressed then move left
                          x -=  RunSpeed;
                          scaleX = -1;
                      }
                  }
  
  
                  //If Dashing is true
                  if (Dashing == true)
                  {
                      //Dash right
                      if (RightDash == true)
                      {
                          stage.addEventListener(KeyboardEvent.KEY_DOWN, SecondDash);
                          stage.removeEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
                          TweenLite.to(this,0,{blurFilter:{blurX:1000}});
                          TweenLite.to(this,0.2,{blurFilter:{blurX:0},x:x + DashAmount,ease:Expo.easeOut});
                          Dashing = false;
                      }
                      else if (LeftDash == true)
                      {
                          //Otherwise dash left
                          stage.addEventListener(KeyboardEvent.KEY_DOWN, SecondDash);
                          stage.removeEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
                          TweenLite.to(this,0,{blurFilter:{blurX:1000}});
                          TweenLite.to(this,0.2,{blurFilter:{blurX:0},x:x - DashAmount,ease:Expo.easeOut});
                          Dashing = false;
                      }
                  }
                  else if (Dashing == false)
                  {
                      stage.removeEventListener(KeyboardEvent.KEY_DOWN, SecondDash);
                  }
  
  
              this.y +=  JumpPower;
          }
  
  
          function SecondDash(event:KeyboardEvent)
          {
              stage.removeEventListener(KeyboardEvent.KEY_DOWN, SecondDash);
  
              if (event.keyCode == 38)
              {
                  TweenLite.to(this,0,{blurFilter:{blurX:0}});
                  TweenLite.to(this,0,{blurFilter:{blurY:1000}});
                  TweenLite.to(this,0.5,{blurFilter:{blurY:0},y:y - DashAmount,ease:Expo.easeOut});
              }
          }
  
          function KeyUp(event:KeyboardEvent)
          {
              stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
              RightDash = false;
              LeftDash = false;
  
              if (event.keyCode == 39)
              {
                  RightKeyPress = false;
              }
  
              if (event.keyCode == 37)
              {
                  LeftKeyPress = false;
              }
  
              if (event.keyCode == 38)
              {
                  UpKeyPress = false;
                  Jumped = false;
              }
          }
      }
  }
  </code></pre>