Actionscript 3 addChild ignored every second attempt

63 views Asked by At

I'm working on a game in Actionscript, and the following code is contained within a function that checks whether or not a key has been pressed on the keyboard. You can ignore all of the other variables, as the only thing that's important is 'OrbRing', a movieclip being loaded from the library.

When the TAB key is pressed, the length of a bar onscreen is decreased by a set amount, and a ring appears onscreen. The first time this is attempted, everything functions normally: the ring appears, and the bar length is decreased.

However, the second time this is attempted, the bar length is decreased, but the OrbRing does not appear.

Strangely enough, the third time this is attempted, everything functions normally again, just like the first time.

But then the fourth time, the issues are the same as the second attempt.

So every even attempt, the addChild code seems to be ignored, but the function is still running since the bar length decreases every time. And every odd attempt, the function performs normally.

I have no idea why this is happening, and I get no error messages. Any help or ideas that might fix this would be greatly appreciated.

if(levelseven==true) {
    if (mykey.keyCode==Keyboard.TAB) {
        if(gear1==true && CPUBAR1_mc.CPUBARYLW_mc.width>=215) {

            CPUBAR1_mc.CPUBARYLW_mc.width-=215;
            addChild(OrbRing);
            OrbRing.x=Orb_mc.x;
            OrbRing.y=Orb_mc.y;
            OrbRing.gotoAndPlay(1);     
        }
    }
}
1

There are 1 answers

0
Brojack On

I've found the solution. For whatever reason (I still don't know why), the movieclip was getting stuck on the first frame on every even attempt. Simply adding a gotoAndPlay(2); instruction made sure the movieclip played every time. Thanks very much for all your help.