Skip to main content
King_Hybrid
Participant
January 7, 2015
Question

How to change standing position of a movieclip after walking animation?

  • January 7, 2015
  • 1 reply
  • 193 views

I'm trying to make a game while also teaching myself actionscript at the same time so right now the project is just a demo. I have a movie clip and in it i have 4 frames. The first is a pair of legs standing facing right, second is legs standing facing left, third a walking animation facing right and the last is the same walking animation facing left. I want the legs to be in the standing position based on what direction they were walking after the left and right arrows are released. this is all done in a regular actionscript 3 file so i don't have any classes so if someone could give me a bit of advice or a reference that would be really great!

this is the code for the main stage

import flash.events.KeyboardEvent;

import flash.events.Event;

var kLeft = false;

var kRight = false;

var kUp = false;

var kDown = false;

player.stop();

addEventListener(Event.ENTER_FRAME, main);

stage.addEventListener(KeyboardEvent.KEY_DOWN, kd);

stage.addEventListener(KeyboardEvent.KEY_UP, ku);

function kd(k:KeyboardEvent){

    if (k.keyCode==37) kLeft=true;

    if (k.keyCode==39) kRight=true;

    if (k.keyCode==38) kUp=true;

    if (k.keyCode==40) kDown=true;

}

function ku(k:KeyboardEvent){

    if (k.keyCode==37) kLeft = false;

    if (k.keyCode==39) kRight = false;

    if (k.keyCode==38) kUp = false;

    if (k.keyCode==40) kDown = false;

}

function main(e:Event){

  if (kLeft){

  player.gotoAndStop("WALKING_L");

  var direction = 1;

  //direction will be 2 for right and 1 for left

  }

  else if(kRight){

  player.gotoAndStop("WALKING_R");

  direction = 2;

  }

  if (kLeft == false){

  if (direction == 1){

  player.gotoAndStop("STANDING_L");

  }

  else if (direction == 2){

  player.gotoAndStop("STANDING_R");

  }

  }

  if (kRight == false){

  if (direction == 1){

  player.gotoAndStop("STANDING_L");

  }

  else if (direction == 2){

  player.gotoAndStop("STANDING_R");

  }

  }

}

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
January 8, 2015

Maybe what you can do is add some more code to the keyup event handler function so that when a left/right walking button is released you also issue the command to stand in that direction.

function ku(k:KeyboardEvent){

    if (k.keyCode==37) {

         kLeft = false;

         player.gotoAndStop("STANDING_L");

    }

    etc...

}