Use DeferredInstanceFromFunction : DeferredInstanceFromFunction « Development « Flex






Use DeferredInstanceFromFunction

Use DeferredInstanceFromFunction
         

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
        
            import mx.core.*;
            import mx.states.*;
            [Bindable]
            public var defInst:DeferredInstanceFromFunction = new DeferredInstanceFromFunction(createMyButton);

            public function createMyButton():Object {
                var newButton:Button = new Button();
                newButton.label = "New Button";
                return newButton;
            }
          
    </mx:Script>
    <mx:states>
        <mx:State name="deferredButton">
            <mx:AddChild relativeTo="{myPanel}" targetFactory="{defInst}" />
        </mx:State>
    </mx:states>
    <mx:Panel id="myPanel" title="Static and dynamic states">
        <mx:Button id="myButton2" label="Add" click="currentState ='deferredButton'" />
        <mx:Button id="myButton3" label="Remove" click="currentState =''" />
    </mx:Panel>
</mx:Application>

   
    
    
    
    
    
    
    
    
  








Related examples in the same category