[AS3 SNIPPET] Detect if Flash movie gain/lose focus

1
2
3
4
5
6
7
8
9
10
11
12
stage.addEventListener(Event.ACTIVATE, activateHandler);
stage.addEventListener(Event.DEACTIVATE, deactivateHandler);

function activateHandler(event:Event):void
{
    trace("activateHandler");
}

function deactivateHandler(event:Event):void
{
    trace("deactivateHandler");
}

Event.ACTIVATE is dispatched when the Flash Player or AIR application gains operating system focus and becomes active.

Event.DEACTIVATE is dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive.