0
votes

I want to ask about this problem. I have a movieclip (instance name : char). Inside it I have 2 frames. The first frame contains a movieclip (it does nothing I forgot why I even bother to make it into movieclip). This first frame has frame label "still".

The second frame also contains a movieclip, inside it contains 12 frame. This second first frame has frame label "run" This is my code

char.gotoAndStop(char.still);

stage.addEventListener(KeyboardEvent.KEY_DOWN, keysDown);
stage.addEventListener(KeyboardEvent.KEY_UP,keysUp);


function keysDown(e:KeyboardEvent):void{
    if(e.keyCode == Keyboard.RIGHT)
    {       
        char.gotoAndStop("run");
        this. char.scaleX = 1;
    }   
}

function keysUp(e:KeyboardEvent):void{
    if(e.keyCode == Keyboard.RIGHT)
    {
        char.gotoAndStop("still");
    }
}

The problem is, when I press RIGHT ARROW button, It moves, but the movieclip (with frame name "run") can't loop or even play complete from frame 1-12, it only plays from frame 1-9 then stop (not go to frame 10 or even loop) is there something wrong with my code?

1
is there any ActionScript at frame 10 of your char movieclip ? - Raptor
your first line should be char.gotoAndStop("still") I don't know what you mean by "This second first frame..."? Likely your parent movieClip is looping causing it's child clip to stop prematurely. If you could post the .fla somewhere it would be easier to see what's going on - BadFeelingAboutThis
ah sorry i have 3 mistakes here 1. it's not "char.gotoAndStop(char.still);" but "char.gotoAndStop('still');" 2. it's not "This second first frame" but "The second frame" 3. in this part "this.char.scaleX = 1", it should be "char.x =+5" to make it move sorry completely in a mess because in actual code I don't use english for naming the instance name and frame name, so when I put it here I edited it - antonius aron

1 Answers

0
votes

Have a look at how often the KEY_DOWN-Event is actually fired. For example by just tracing.

function keysDown(e:KeyboardEvent):void{
    if(e.keyCode == Keyboard.RIGHT)
    {       
        trace("pressed");
        char.gotoAndStop("run");
        this. char.scaleX = 1;
    }   
}

You will realize that the event is thrown WHILE the Key is pressed, not only once. You actually call the gotoAndStop("run") repeatedly, which makes your animation mc restart all the time.