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>
<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>
<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>