Detecting when a WindowedApplication is activated or deactivated in Adobe AIR

by Peter deHaan on December 20, 2008 · 0 comments

in WindowedApplication

The following example shows how you can detect when an Adobe AIR application gains or loses focus by listening for the windowActivate and windowDeactivate events.

Full code after the jump.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://airexamples.com/2008/12/20/detecting-when-a-windowedapplication-is-activated-or-deactivated-in-adobe-air/ -->
<mx:WindowedApplication name="WindowedApplication_applicationActivate_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        windowActivate="windowedApplication_windowActivate(event);"
        windowDeactivate="windowedApplication_windowDeactivate(event);">
 
    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.events.AIREvent;
            import mx.managers.PopUpManager;
 
            private var alert:Alert
 
            private function windowedApplication_windowActivate(evt:AIREvent):void {
                lbl.text = evt.type;
                if (alert) {
                    PopUpManager.removePopUp(alert);
                }
            }
 
            private function windowedApplication_windowDeactivate(evt:AIREvent):void {
                lbl.text = evt.type;
                alert = Alert.show("WindowedApplication deactivated");
            }
        ]]>
    </mx:Script>
 
    <mx:Label id="lbl" fontSize="32" />
 
</mx:WindowedApplication>

{ 0 comments… add one now }

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Previous post:

Next post: