Flex编程注意之直接获取某个组件的对象(this[]用法)通过id获取
有这样一个需求:假如你new了一百次Button,同时这些button的id分别赋值如btn1.id = "button1"; btn2.id = "button2";以此类推。
<?xml version="1.0"?> ?
<mx:Application xmlns:mx="http://www.adobe.com/2006/mx
?
?<mx:Script>
?? ?<![CDATA[ ?
?? ?private var newFontStyle:String; ?
?? ?private var newFontSize:int; ?
???
?? ?public function changeStyle( s : String ) : void { ?
?? ? ? ?s = "button" + s;?? ? ?
?? ? ? ?this[ s ].setStyle( "fontSize",20 ); ?
?? ?} ?
?? ?]]>
?? ?</mx:Script> ?
??
?? ?<mx:Button id="button1" click="changeStyle('2')" label="Button 1" /> ?
?? ?<mx:Button id="button2" click="changeStyle('1')" label="Button 2" /> ?
</mx:Application>
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |