var state:State = new State(); var button:Button = new Button(); button.label = "LABEL"; var addChild:AddChild = new AddChild(vbox, button); state.overrides = [addChild]; state.name = "buttonState"; states.push(state);
这里被重写的数组是将被使用的State 的重写列表,就是,哪些功能将被定义,哪些特定的State 属性将被定义,比如任何SetProperty 或SetStyle 操作,所有为State 定义的重写都是实现了IOverride 接口,一般包含下列: AddChild RemoveChild SetEventHandler SetProperty SetStyle (For more information on the IOverride interface, see Recipe 11.15.) 下面是完整的代码,注意创建Transition 对象,添加属性,指定toState 和fromState 属性的这些方法:
+展开
-XML
<mx:VBoxxmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300"> <mx:Script> <![CDATA[ import mx.controls.Button; import mx.states.AddChild; import mx.states.State; import mx.states.Transition; import mx.effects.Move; publicfunction addTransitions():void { var transition:Transition = new Transition(); var move:Move = new Move(); move.duration=400; move.target = vbox; transition.fromState = "buttonState"; transition.toState = "*"; transition.effect = move; transitions.push(transition); } publicfunction addState():void { var state:State = new State(); var button:Button = new Button(); button.label = "LABEL"; var addChild:AddChild = new AddChild(vbox, button); state.overrides = [addChild]; state.name = "buttonState"; states.push(state); }