I’m trying to get a quick replay command, “pressing space returns the scene to the previous frame”.
var keyArray:Array = new Array();
var i:Number;
for(i=0;i<222;i++){
keyArray.push([i,false]);
}
stage.addEventListener(KeyboardEvent.KEY_DOWN,checkKeysDown);
stage.addEventListener(KeyboardEvent.KEY_UP,checkKeysUp);
this.addEventListener(Event.ENTER_FRAME,
UpdateScreen);
function UpdateScreen(event:Event):void{
if(isKeyDown(39)==true){
gotoAndPlay(40);
}
if(isKeyDown(39)==false){
trace("Released");
}
}
function checkKeysDown(event:KeyboardEvent):void{
keyArray[event.keyCode][1]=true;
}
function checkKeysUp(event:KeyboardEvent):void{
keyArray[event.keyCode][1]=false;
}
function isKeyDown(X){
return keyArray[X][1];
}
The current function returns me to a previous frame (40), however the event does not stop, rather it keeps on adding new events ontop of each other once it returns to main frame.
The main frame being where the actionscript is executed.
Anyone know how to solve this?