# Need help with movieclips

**URL:** <https://forum.kirupa.com/t/need-help-with-movieclips/239086>\
**Category:** Uncategorized\
**Created:** [September 18, 2007, 4:58pm UTC](https://forum.kirupa.com/t/need-help-with-movieclips/239086 "2007-09-18T16:58:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jedi\_jinn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@jedi\_jinn](https://forum.kirupa.com/u/jedi_jinn)\
**Post date:** [September 18, 2007, 4:58pm UTC](https://forum.kirupa.com/t/need-help-with-movieclips/239086/1 "2007-09-18T16:58:58Z")

</div>

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:

```auto

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.
