Yes, its me, da newb. releasing help

Hello all, I have been programming a sideScrolling action game, and I have run into yet another problem. When I press the punch button, The character will play the “punch” sequence, but if you hold down the key, he will keep punching. I have devised a code, but it still is messed.

 
onClipEvent (enterFrame) {
	if (!this.punching) {
		if (Key.isDown(90)) {
			this.gotoAndStop("punch");
			this.punching = true;
			}
	 }
}
onClipEvent (keyUp) {
	if (Key.getCode() == 90) {
		this.punching = false;
	 }
}

If anyone knows, please reply. Thanks:thumb:.

shouldn’t ya just put it so goto the non punching frame on the second one?

shouldn’t ya just put it so goto the non punching frame on the second one?

No, that would just make him stop punching when you release it. What I want the character to do is punch only ounce if you hold down, or press the punching key unless you release it. If I dont make sence, tell me (I cant explain things worth crap :crazy: ).

I thin kwhat you want is that when you hold the punch key it continually plays the punching sequence of frames, but when you realease you want him to stop punching, but still complete the sequence:


onClipEvent (keyDown) {
     if (Key.getCode() == 90) {
          this.gotoAndPlay("punch");
          this.punching = true;
          this.donepunching = false;
     }
}
onClipEvent (keyUp) {
     if (Key.getCode() == 90) {
          this.punching = false;
     }
}
//on last frame of punching sequence
if(this.punching) {
     this.gotoAndPlay("punch");
} else {
     this.stop();
     this.donepunching = true;
}
/*CHANGES
-on keyDown instead of onEnterFrame
-gotoAndPlay instead of gotoAndStop in keyDown block.
-Frame actions
-added done punching variable so you know he is still punching even when the key isn't pressed because you don't want his punches to become in effective just because you released the key
*/

</FONT>

[font=Courier New]Hope that helps.[/font]

Thanks :smiley: