Flex 遍历组件 TextInput

spark组件:

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009
xmlns:s="library://ns.adobe.com/flex/spark" 
xmlns:mx="library://ns.adobe.com/flex/mx" width="600" height="261"> 

<s:layout> 
<s:BasicLayout/> 
</s:layout> 

<fx:Script> 
<![CDATA[ 
import spark.components.supportClasses.SkinnableComponent; 
private var result:String = ""; 

protected function btnRetrieve_clickHandler(event:MouseEvent):void 

result = ""; 
retrieve(this,""); 
txtResult.text = result; 


private function retrieve(obj:Object, prefix:String):void 

if(obj is SkinnableComponent) 

if(obj is TextInput) 

result +=prefix+TextInput(obj).text+"/r/n"; 

else 

var nums:int = 0; 
if(obj.hasOwnProperty("numElements")) 
nums = obj.numElements; 
for(var i:int = 0; i<nums; i++) 

var component:Object = obj.getElementAt(i); 
retrieve(component,prefix); 




else 

var nums:int = 0; 
if(obj.hasOwnProperty("numChildren")) 
nums = obj.numChildren; 
for(var i:int = 0; i<nums; i++) 

var component:Object = obj.getChildAt(i); 
retrieve(component,prefix); 



]]> 
</fx:Script> 

<s:Panel id="sPanel" title="Spark Panel" width="414"> 
<s:TextInput x="10" y="32" id="sPanel_textinput"/> 
<s:Button x="199" y="32" label="按钮" id="sPanel_button"/> 

</s:Panel> 
<mx:Panel id="mPanel" title = "MX Panel" x="0" y="135" width="414" height="116" layout="absolute"> 
<s:TextInput x="10" y="15" id="mPanel_textinput"/> 
<s:Button label="按钮" x="200" y="16" id="mPanel_button"/> 
</mx:Panel> 
<s:Button x="519" y="10" label="遍历控件" id="btnRetrieve" click="btnRetrieve_clickHandler(event)"/> 
<s:TextArea x="422" y="39" height="212" width="168" id="txtResult"/> 
</s:Application>

mx组件:

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
layout="absolute"> 
<mx:Script> 
<![CDATA[ 
import mx.core.Container; 

private function walkAllNodes():void 

walk(box.getChildren()) 


private function walk(children:Array):void 

for each(var child:Object in children) { 

if (child is Container && Container(child).getChildren()) { 
walk(Container(child).getChildren()); 
} else if (child is TextInput){ 
var value:String = TextInput(child).text; 
trace(value); 



]]> 
</mx:Script> 
<mx:VBox id="box"> 
<mx:HBox> 
<mx:Label text="website"/> 
<mx:TextInput id="txtInput" text="1"/> 
<mx:HBox> 
<mx:TextInput text="2"/> 
<mx:HBox> 
<mx:TextInput text="3"/> 
</mx:HBox> 
<mx:HBox> 
<mx:TextInput text="4"/> 
</mx:HBox> 
<mx:TextInput text="5"/> 
</mx:HBox> 
</mx:HBox> 
<mx:Button label="walkAllNodes" click="walkAllNodes()" /> 
</mx:VBox> 
</mx:Application>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值