组件中,所有的ID都是可以对外访问的。但是组件中的子控件,是无法提供对外事件支持的,这时需要做事件的转发功能,如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" width="292" height="226">
<mx:Metadata>
[Event(name="myComponentTextChange", type="flash.events.Event" )]
</mx:Metadata>
<mx:Script>
<![CDATA[
[Bindable("text")]
[Inspectable(defaultValue="hello word")]
public function set myComponentText(value:String):void
{
inputText.text=value
}
public function get myComponentText():String{
return inputText.text
}
]]>
</mx:Script>
<mx:TextArea id="inputText" change="this.myComponentText=inputText.text;
this.dispatchEvent(new Event('myComponentTextChange'))" width="264" height="183" />
</mx:TitleWindow>
--------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:wxsr="components.*" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<wxsr:TestComponent id="testComponent" enterFrame="trace(testComponent.myComponentText)" myComponentTextChange="trace('------')">
</wxsr:TestComponent>
</mx:Application>