Using a compound String to get a reference to Flex 3 object


/ Published in: ActionScript 3
Save to your folder(s)

Using a string built at runtime to reference objects in Flex. From the help docs.


Copy this code and paste it in your HTML
  1. <?xml version="1.0"?>
  2. <!-- usingas/FlexComponents.mxml -->
  3. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
  4. <mx:Script><![CDATA[
  5. public function changeLabel(s:String):void {
  6. s = "myButton" + s;
  7. this[s].setStyle("fontStyle","italic");
  8. this[s].setStyle("fontSize","18");
  9. }
  10. ]]></mx:Script>
  11.  
  12. <mx:Button id="myButton1" click="changeLabel('2')" label="Change Other
  13. Button's Styles"/>
  14. <mx:Button id="myButton2" click="changeLabel('1')" label="Change Other
  15. Button's Styles"/>
  16. </mx:Application>

URL: http://livedocs.adobe.com/labs/flex3/html/help.html?content=usingas_3.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.