Reputation: 47
I want to achieve this in my game http://www.emanueleferonato.com/2011/03/29/pausing-a-flash-game-or-movie-detecting-its-focus/
everything works fine(game is paused) but the screen is not "drawn" but if I move the mouse over the swf the screen appears
private function onDeactivate(e:Event):void {
pauseGame=true;
addChild(FocusScreen);
if(musicOn==true){
musicCh.stop();
}
stage.frameRate = 0;
}
UPDATE: this only occurs if i set stage framerate to 0 this works but I need to set the framerate 0
private function onDeactivate(e:Event):void {
pauseGame=true;
addChild(FocusScreen);
if(musicOn==true){
musicCh.stop();
}
}
Upvotes: 0
Views: 63
Reputation: 18747
Call e.updateAfterEvent()
after setting stage's frame rate. This forces a single redraw of the stage, after that the stage's framerate set to 0 kicks in, and the stage does not get redrawn anymore until you restore its framerate.
Update: apparently it is a bug in Flash player 11.3 (maybe more of FP11) that wasn't in place with FP10, so the "naked" approach as in the tutorial worked for me when I used a debugger FP10 that comes with FlashDevelop, but didn't work when I have tried it in my FF with FP11.3 installed. So the workaround is as follows: Add a bogus Sprite
object into your code, do not add it anywhere, it will serve as a recipient of a custom MouseEvent
event for the sole purpose of calling updateAfterEvent()
. This worked for me to display a custom DisplayObject that signifies the paused state.
private var pausedRecipient:Sprite=new Sprite();
// do not add child so that its listener won't trigger on user input
pausedRecipient.addEventListener(MouseEvent.CLICK,uae);
private function uae(e:MouseEvent):void {e.updateAfterEvent();}
private function onDeactivate(e:Event):void {
pauseGame=true;
addChild(FocusScreen);
if(musicOn==true){
musicCh.stop();
}
pausedRecipient.dispatchEvent(
new MouseEvent(MouseEvent.CLICK,true, true, -1, -1, stage));
// ^ this does the trick of indirect call of updateAfterEvent()
}
Upvotes: 1