Mega Code Archive

 
Categories / Flex / Effects
 

Setting event handlers with State

<?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">     <mx:Script>                  import flash.events.Event;         private function handlerBase():void {             ta1.text = "handler 1";         }         private function handlerState1(event:Event):void {             ta1.text ="handler 2.";         }         private function handlerState3(theString:String):void {             ta1.text ="param: "+ theString;         }            </mx:Script>     <mx:states>         <mx:State name="State1">             <mx:SetEventHandler target="{b1}" name="click" handlerFunction="handlerState1" />             <mx:SetProperty target="{b1}" name="label" value="State 1" />         </mx:State>         <mx:State name="State2">             <mx:SetEventHandler target="{b1}" name="click" handler="ta1.text='listener';" />             <mx:SetProperty target="{b1}" name="label" value="State 2" />         </mx:State>         <mx:State name="State3">             <mx:SetEventHandler target="{b1}" name="click" handler="handlerState3('my param');" />             <mx:SetProperty target="{b1}" name="label" value="State 3" />         </mx:State>     </mx:states>     <mx:Button id="b1" label="Click Me: Base State" click="handlerBase();" />     <mx:TextArea id="ta1" height="100" width="50%" />     <mx:Button label="state 1" click="currentState='State1';" />     <mx:Button label="state 2" click="currentState='State2';" />     <mx:Button label="state 3" click="currentState='State3';" />     <mx:Button label="Start" click="currentState='';" /> </mx:Application>