Flex creationPolicy策略

在Flex中,利用state进行状态和页面的迁移与变换,中间的AddChild IOverride有一个creationPolicy,这个属性有三种设置,分别如下:

 

 

AUTO:默认设置,只有在状态改变的时候,即时的生成新增组件;

ALL:在Application加载的时候,就加载了新增的组件,在状态改变的时候显示;

NONE:需要手动的调用该addChild Instance createInstance方法生成新增组件,方能显示;

 

示例代码如下:

 

<?xml version="1.0"?> <!-- states/StatesCreationPolicy.mxml --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initButton();"> <mx:Script> <!--[CDATA[ // Because the cpAll view state creates the Button control // at application startup, you can access the control to // set the label before the first switch // to the cpAll view state. public function initButton():void { newButton.label="cpAll Button"; } ]]--> </mx:Script> <mx:states> <!-- Create the Button control at application startup. --> <mx:State name="cpAll"> <mx:AddChild relativeTo="{myPanel}" creationPolicy="all"> <mx:Button id="newButton"/> </mx:AddChild> </mx:State> <!-- Create the Button control when you want to create it. --> <mx:State name="cpNone"> <mx:AddChild id="noCP" relativeTo="{myPanel}" creationPolicy="none"> <mx:Button label="cpNone button"/> </mx:AddChild> </mx:State> </mx:states> <mx:Panel id="myPanel" title="Static and dynamic states" width="300" height="150"> <!-- Change to the cpAll view state. --> <mx:Button label="Change to cpAll state" click="currentState = currentState == 'cpAll' ? '' : 'cpAll';"/> <!-- Create the Button control for the noCP state that uses creationPolicy=none. If you do not click this button before changing to the cpNone view state, the view state does nothing because the Button control does not exist. --> <mx:Button label="Explicitly create a button control" click="noCP.createInstance();"/> <!-- Change to the cpNone view state. --> <mx:Button label="Change to noCP state" click="currentState = currentState == 'cpNone' ? '' : 'cpNone';"/> </mx:Panel> </mx:Application>

你可能感兴趣的:(function,Flex,application,Access,button)