I’m just learning AS3 and for an assignment I’m making a very basic brawler. I’m already beginning and I’ve run into a bump, and the kicker is I know how to do it easily in AS2 .
My issue is getting the punch animation to play all the way through no matter how quick the button is pushed. IE, I’ll click space (the punch button) and it’ll only play the first couple frames of the animation. How can I get it to play the whole animation?
I have my animations stored on separate frames in the movie clip playerHolder. By using gotoAndStop() I plan on accessing them.
I detect the space press and set a variable, punchVar to 1.
if(e.keyCode == Keyboard.SPACE)
{
punchVar = 1;
}
This is used in the function punchLaunch which is checked for in an Enter Frame listener.
this.addEventListener(Event.ENTER_FRAME, punchLaunch);
When punchVar is 1, play the punch and set punchVar to 0 (to stop the Enter Frame from continuously repeating the first frame). When the punch animation = 6 I want it to go back to the idle animation.
private function punchLaunch(e:Event):void
{
if(punchVar == 1)
{
playerHolder.punch();
punchVar = 0;
}
if(playerHolder.playerPunch.currentFrame == 6)
{
playerHolder.gotoAndStop(1);
}
}
I’m stumped on this. Any help would be greatly appreciated.