Disabling an Application in Flex 3

The following example shows how you can disable an entire Flex Application in Flex 3 by setting the Boolean enabled property on the application object.

Full code after the jump.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/08/14/disabling-an-application-in-flex-3/ -->
<mx:Application name="Application_enabled_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        backgroundColor="white"
        verticalAlign="middle"
        initialize="init();">
 
    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
 
            protected const tmr:Timer = new Timer(3000, 1);
 
            protected function init():void {
                tmr.addEventListener(TimerEvent.TIMER_COMPLETE, tmr_complete);
            }
 
            protected function tmr_complete(evt:TimerEvent):void {
                application.enabled = true;
                appControlBar.enabled = true;
                Alert.show("I'm back!", "Alert title");
            }
 
            protected function btn_click(evt:MouseEvent):void {
                application.enabled = false;
                appControlBar.enabled = false;
                tmr.start();
            }
        ]]>
    </mx:Script>
 
    <mx:ApplicationControlBar id="appControlBar" dock="true">
        <mx:Button id="btn"
                label="Disable application (3 seconds)"
                themeColor="red"
                click="btn_click(event);" />
    </mx:ApplicationControlBar>
 
    <mx:HBox horizontalCenter="0" verticalCenter="0">
        <mx:TextInput id="txtInput" text="Halo TextInput" />
        <mx:TextArea id="txtArea" text="Halo TextArea" />
        <mx:List id="list"
                dataProvider="[The,Quick,Brown,Fox,Jumps,Over,The,Lazy,Dog]"
                verticalScrollPolicy="on"
                width="100" />
    </mx:HBox>
 
</mx:Application>

For an example of disabling a Flex 4 application, see “Disabling a Spark Application in Flex 4”.