Need help with movieclips

Hi, I’m new to AS3, but not to programming or OOP. However, AS3 and it’s displayobjects seem to be confusing me alot. I’m trying to make a very simple game for my own learning purposes, but can’t seem to get the movieclips to play correctly in AS3. I saw some AS2 examples, but they dont seem to transfer well to AS3.

Here’s the Code:


hero.step=2;
hero.attack = false;
hero.stance= 1; 
var rightDown:Boolean = false;
var leftDown:Boolean = false;
var spaceDown:Boolean = false;
var keySpace = false;

      
    
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownListener);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpListener);
var timer:Timer = new Timer(20);
timer.addEventListener(TimerEvent.TIMER, moveClip);
timer.start();

function keyDownListener (e:KeyboardEvent):void 
{
    
    if(e.keyCode==Keyboard.LEFT)
    {        
        leftDown=true;
            
    }
    else if(e.keyCode==Keyboard.RIGHT)
    {
        rightDown=true;

    }
    else if(e.keyCode==Keyboard.SPACE)
    {
        spaceDown=true;
    }
            

}

function keyUpListener (e:KeyboardEvent):void 
{
    if(e.keyCode==Keyboard.LEFT)
        leftDown=false;
    if(e.keyCode==Keyboard.RIGHT)
        rightDown=false;
    if(e.keyCode==Keyboard.SPACE)
        spaceDown=false;
    hero.gotoAndStop("stance");
    
}

function moveClip (e:TimerEvent)
{
    if(leftDown)
    {
            hero.scaleX = 1.0;
            hero.stance=0;
            hero.x-=hero.step;
            if(hero.currentLabel != "walkingleft")
                hero.gotoAndStop("walkingleft");
    }
    if(rightDown)
    {
            hero.scaleX = -1.0;
            hero.stance=1;
            hero.x+=hero.step;
            if(hero.currentLabel != "walkingleft")
                hero.gotoAndStop("walkingleft");
        
    }
    if(spaceDown && keySpace==false)
    {
            hero.attack = true;
    }
    if(hero.attack)
    {
        if(hero.currentLabel != "attackleft")
        {
            hero.gotoAndStop("attackleft");
        }
        if(hero["nestAttackLeft"] != null && hero["nestAttackLeft"].currentFrame == 11)
        {
            
            hero.attack=false;
        }

    }

    if(spaceDown)
    {
        keySpace= true;
    }
    else
    {
        keySpace = false;
    }
    
    e.updateAfterEvent();
    
}

What I’m trying to do is make the hero move across the screen whenever I press left or right on my keyboard and at the same time have it play the walking animation that is nested in hero_mc. I’ve got the walking down , but not the attacking animation.

When I press space the hero’s attack animation plays non-stop. I checked hero_mc.attack and it is set to false after the last frame of the attack animation is played. This makes no sense to me in terms of logic. Perhaps there’s something to AS3 that I don’t quite understand?

Also, if you have tips for me to improve the above code please tell me.
Thank you.