Using different creation policies
<?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initButton();"> <mx:Script> public function initButton():void { newButton.label="creationPolicyAll Button"; } </mx:Script> <mx:states> <mx:State name="creationPolicyAll"> <mx:AddChild relativeTo="{myPanel}" creationPolicy="all"> <mx:Button id="newButton" /> </mx:AddChild> </mx:State> <mx:State name="creationPolicyNone"> <mx:AddChild id="nocreationPolicy" relativeTo="{myPanel}" creationPolicy="none"> <mx:Button label="creationPolicyNone button" /> </mx:AddChild> </mx:State> </mx:states> <mx:Panel id="myPanel" title="Static and dynamic states" width="300" height="150"> <mx:Button label="Change to creationPolicyAll state" click="currentState = currentState == 'creationPolicyAll' ? '' : 'creationPolicyAll';" /> <mx:Button label="Explicitly create a button control" click="nocreationPolicy.createInstance();" /> <mx:Button label="Change to nocreationPolicy state" click="currentState = currentState == 'creationPolicyNone' ? '' : 'creationPolicyNone';" /> </mx:Panel> </mx:Application>