Mega Code Archive

 
Categories / Flex / Event
 

Pass a string and Event object to method

<?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">     <mx:Script>         public function runMove(dir:String, e:Event):void {             if (dir == "up") {                 moveableButton.y = moveableButton.y - 5;             } else if (dir == "down") {                 moveableButton.y = moveableButton.y + 5;             } else if (dir == "left") {                 moveableButton.x = moveableButton.x - 5;             } else if (dir == "right") {                 moveableButton.x = moveableButton.x + 5;             }         }       </mx:Script>     <mx:Canvas height="100%" width="100%">         <mx:Button id="moveableButton"             label="{moveableButton.x.toString()},{moveableButton.y.toString()}"             x="200" y="200" width="80" />     </mx:Canvas>     <mx:VBox horizontalAlign="center">         <mx:Button id="b1" label="Up" click='runMove("up",event);' width="50" />         <mx:HBox horizontalAlign="center">             <mx:Button id="b2" label="Left" click='runMove("left",event);' width="50" />             <mx:Button id="b3" label="Right" click='runMove("right",event);' width="50" />         </mx:HBox>         <mx:Button id="b4" label="Down" click='runMove("down",event);' width="50" />     </mx:VBox> </mx:Application>