[AS3] Game spacebar press loop
I am making a game where.. a character is standing on the left side of a cliff. Because I am a newbie AS3 programmer, I am using simple timeline navigation. Let me explain:
Character stands on cliff. He clicks on platform on other side of swamp. This then moves him on to another frame where I have looped a group of frames. He does an animation that makes himself prepare to jump. They all have different levels of whether he will make it to the other side.
I have labelled them all like this:
startframe is C2.1
Trips over into water is frame label C2.2
Jumps but doesnt reach platform C2.3
Jumps and successfully reaches over side C2.3
here is the code below for each timed event.
__________________________________________
stage.addEventListener(KeyboardEvent.KEY_DOWN, spacePress_01);
function spacePress_01(evt:KeyboardEvent):void {
if (evt.keyCode==Keyboard.SPACE) {
gotoAndStop("(whatever frame pressed");
}
}
______________________________________________
so if the user presses space too early he wont make the platform. If he doesnt press anything at all he trips into the water. Then I have a frame action that says gotoandstop at C2 which is back to start. (when he has to click other platform to intiate the game again. Understood?
However when that frame is looped back to start the frame rate goes OUT OF CONTROL!
It starts speeing up the frame rate... then eventually coming to a stable FPS. (24)
I tryed this on the frames
___________________________________
stage.framerate = 24;
didnt do anything.
And also with the spacepress I have to click on stage before it functions. how can i give it focus?
Thanks
|