<?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.IFlexDisplayObject;
import mx.controls.Alert;
private function test():void{
var n:int=canvas.numChildren;
for (var i:int = 0; i < n; i++)
{
var child:Object = IFlexDisplayObject(DisplayObjectContainer(canvas).getChildAt(i));
Alert.show(child.toString());
if (child is Button)
{
Alert.show(child.toString());
}
if (child is Label)
{
Alert.show(child.toString());
}
}
}
]]>
</mx:Script>
<mx:Canvas x="140" y="94" width="419" height="334" id="canvas">
<mx:Button x="52" y="47" label="Button" id="btn"/>
<mx:CheckBox x="52" y="107" label="Checkbox" id="chk"/>
<mx:ComboBox x="52" y="159" id="com"></mx:ComboBox>
<mx:Image x="64" y="225" id="img"/>
<mx:Label x="52" y="293" text="Label" />
</mx:Canvas>
<mx:Button x="46" y="29" label="Button" click="test();"/>
</mx:Application>
控件没有id可以。