1 Reply Latest reply on May 7, 2016 1:51 PM by John T Smith

    Play a full movie clip with one keyboard press

    xvertion121

      i am facing a problem more then a month and not finding any solution and now i am pretty frustrated. As my last resort i am posting it here.

       

      I am making a hero move with the keyboard. I have 4 animations.

      1. Standby mode
      2. walk front
      3. walk behind
      4. jump

      It's working well so far, but the problem I'm facing in jumping the player is having to hold down the key to jump. I don't want the player to be required to hold the key to perform jumping. I want to play the full Movie Clip (lets say 10 frame with different image) with one key press, and honestly I don't know how to do it.

      plz help

       

      Here is the file Kim movement.zip - Google Drive

      here is my code

      import flash.display.Stage;
      import flash.events.KeyboardEvent;
      import flash.ui.Keyboard;
      import flash.display.MovieClip;
      import flash.events.Event;

      kim
      .gotoAndStop("kim Stand");

      var grav:int = 0;
      var floor = 450;
      var dPressed:Boolean = false;
      var aPressed:Boolean = false;
      var jumping:Boolean = false;

      stage
      .addEventListener(KeyboardEvent.KEY_DOWN , keyDownHandaler);
      stage
      .addEventListener(KeyboardEvent.KEY_UP , KeyUpHandaler);
      stage
      .addEventListener(Event.ENTER_FRAME , gameLoop);

      function keyDownHandaler(Devent:KeyboardEvent):void
      {
        
      if (Devent.keyCode == Keyboard.D)
        
      {
        dPressed
      = true;
        
      }
        
      else if (Devent.keyCode == Keyboard.A)
        
      {
        aPressed
      = true;
        
      }
        
      else if (Devent.keyCode == Keyboard.W && !jumping)
        
      {
        jumping
      = true;
        
      }
      }

      function KeyUpHandaler (Uevent:KeyboardEvent):void
      {
        
      if (Uevent.keyCode == Keyboard.D)
        
      {
        dPressed
      = false;
        kim
      .gotoAndStop("kim Stand");
        
      }
        
      else if(Uevent.keyCode == Keyboard.A)
        
      {
        aPressed
      = false;
        kim
      .gotoAndStop("kim Stand");
        
      }

        
      else if(Uevent.keyCode == Keyboard.W)
        
      {
        jumping
      = false;
        kim
      .gotoAndStop("kim Stand");
        
      }


      }

      function gameLoop(Levent:Event):void
      {
        
      if (dPressed)
        
      {
        kim
      .x += 5;

        kim
      .gotoAndStop("kim Move Right");
        
      }
        
      else if(aPressed)
        
      {
        kim
      .x -= 5;
        kim
      .gotoAndStop("kim Move Left");
        
      }

        
      else if(jumping)
        
      {
        kim
      .gotoAndStop("kim Jump");
        kim
      .y -= 10;

        
      }

        gravity
      ();

      }

      function gravity ():void
        
      {
        kim
      .y += grav;
        
      if (kim.y+kim.height/2 <floor){
        grav
      ++;
        
      }

        
      else {
        grav
      = 0;
        kim
      .y = floor - kim.height/2 ;

        
      }

        
      }