Skip to content

Instantly share code, notes, and snippets.

@Hasufel
Last active August 29, 2015 13:56
Show Gist options
  • Save Hasufel/8801778 to your computer and use it in GitHub Desktop.
Save Hasufel/8801778 to your computer and use it in GitHub Desktop.
package;
import flash.events.Event;
import flash.events.FocusEvent;
import flash.Lib;
import flash.display.Sprite;
import flash.display.StageScaleMode;
class TestActivate extends Sprite {
public function new() {
super();
haxe.Timer.delay(init,100);
}
private function init():Void {
Lib.current.stage.addEventListener(Event.DEACTIVATE, onDeactivate);
Lib.current.stage.addEventListener(FocusEvent.FOCUS_IN, onFocusIn);
Lib.current.stage.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
}
private function onFocusIn(e:Event=null) {
trace('App received focus');
}
private function onFocusOut(e:Event=null) {
trace('App lost focus');
}
private function onDeactivate(e:Event=null) {
trace('App is deactivated');
Lib.current.stage.frameRate = 1;
Lib.current.stage.removeEventListener(Event.DEACTIVATE, onDeactivate);
Lib.current.stage.addEventListener(Event.ACTIVATE, onActivate);
}
private function onActivate(e:Event=null) {
trace('App is activated');
Lib.current.stage.frameRate = 60;
Lib.current.stage.removeEventListener(Event.ACTIVATE, onActivate);
Lib.current.stage.addEventListener(Event.DEACTIVATE, onDeactivate);
}
static public function main() {
var stage = Lib.current.stage;
stage.scaleMode = StageScaleMode.NO_SCALE;
Lib.current.addChild(new TestActivate());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment