用户名: 密   码:
   飞诺网 加入收藏
飞诺网 网站开发 VBScript ASP Asp.net Jsp php XML CGI-Perl 搜索引擎 ajax web技术
XML系列教程 XML实例 XML技术文档

您当前的位置:飞诺网 >>  网站开发 >>  XML >> XML技术文档

flex 动态给控件赋值,通过反射遍历MXML中的组件

www.diybl.com    时间 : 2008-05-05  作者:佚名   编辑:本站 点击:   [ 评论 ]

flex 动态给控件赋值,通过反射遍历MXML中的组件。当有100个mx:TextInput 需要给他们text属性赋值的时候,如果id存在规律可以用for,但如果id完全没规律的话那麽就需要用下面方法了,通过反射

<?xml version="1.0" encoding="utf-8"?>
<mx:Application  xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Canvas id="s" width="263" height="193" backgroundImage="../img/infobg.png">
<mx:Canvas id="k" width="243" height="141.1" x="10" y="41.9">
<mx:Script> 
<![CDATA[   
import mx.controls.TextInput;  
import mx.controls.Button;   
public function dkdk(){   
 var instanceInfo:XML=describeType(this);//通过反射机制取出当前MXML中的信息   
 var properties:XMLList =instanceInfo..accessor.(@type=="mx.controls::TextInput")   
 trace(instanceInfo..accessor.(@type=="mx.controls::TextInput"));   
 for each(var propertyInfo:XML in properties){     
  var propertyName:String =propertyInfo.@name;//此处取出的为textinput的id     
  TextInput(this[propertyName]).text="1111";   
  }       
 } 
]]>
</mx:Script>
<mx:TextInput id="a" x="0" y="1" width="90" height="17.6"/>
<mx:TextInput id="b" x="89.05" y="1" width="117.899994" height="17.6"/>
<mx:TextInput x="0" y="20" width="90" height="17.6"/>
<mx:TextInput x="89.05" y="20" width="117.899994" height="17.6"/>
<mx:TextInput x="0" y="39" width="90" height="17.6"/>
<mx:TextInput x="89.05" y="38" width="117.899994" height="17.6"/>
<mx:TextInput x="0" y="58" width="90" height="17.6"/>
<mx:TextInput x="89.05" y="58" width="117.899994" height="17.6"/>
<mx:TextInput x="0" y="77" width="90" height="17.6"/>
<mx:TextInput x="89.05" y="77" width="117.899994" height="17.6"/>
<mx:TextInput x="0" y="96" width="90" height="17.6"/>
<mx:TextInput x="89.05" y="96" width="117.899994" height="17.6"/>
<mx:TextInput id="p" x="0" y="115" width="90" height="17.6"/>
<mx:TextInput x="89.05" y="115" width="117.899994" height="17.6"/>
</mx:Canvas>
</mx:Canvas>
<mx:Button x="332" y="107" label="Button" click="dkdk()"/>
</mx:Application>

如果图片或页面不能正常显示请点击这里
XML技术文档推荐文章

文章评论