0

I've been looking to make an animation using ActionScript 3.0 in Adobe Flash Professional where a character (John) can be moved by the viewer using the arrow keys. I've made two sprites, John (the default standing character) and JohnLeg (the character with a raised leg), and I switch between them when the up key is pressed to make it look like he is walking. I've tried this by making one invisible and the other visible.

However, at the moment it only shows JohnLeg for 0 seconds, so I believe I need to set a time delay when he moves to show JohnLeg for half a second before switching back.

My code only considers the up key at the moment, and most of it was taken using the code snippets in Adobe Flash:

var upPressed:Boolean = false;

John.addEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey_4);
stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed_4);
stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed_4);

function fl_MoveInDirectionOfKey_4(event:Event)
{

JohnLeg.visible = false;
JohnLeg.x = John.x
JohnLeg.y = John.y

if (upPressed)
{
    JohnLeg.visible = true;
    John.visible = false;
    John.y -= 5;
        //set time delay here
    JohnLeg.visible = false;
    John.visible = true;
}
}

function fl_SetKeyPressed_4(event:KeyboardEvent):void
{
switch (event.keyCode)
{
    case Keyboard.UP:
    {
        upPressed = true;
        break;
    }
}

function fl_UnsetKeyPressed_4(event:KeyboardEvent):void
{
switch (event.keyCode)
{
    case Keyboard.UP:
    {
        upPressed = false;
        break;
    }

1 Answers1

0

You could try setTimeout. Here it some help doc http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000602.html

Pan
  • 2,101
  • 3
  • 13
  • 17