public override function addChild(child:DisplayObject):DisplayObject
雖然參數(shù)child的類型是DisplayObject,但是它必須實(shí)現(xiàn)IUIComponent接口(所有Flex組件都實(shí)現(xiàn)了這一接口),才能添加。 如果要在Application里添加Sprite,可以先把它裝進(jìn)一個(gè)UIComponent,然后再添加這個(gè)UIComponent: 官方的說(shuō)法: * <p><b>Note: </b>While the <code>child</code> argument to the method * is specified as of type DisplayObject, the argument must implement * the IUIComponent interface to be added as a child of a container. * All Flex components implement this interface.</p> 例子:
復(fù)制代碼 代碼如下:
import mx.core.UIComponent;private function init():void { var sp:Sprite = new Sprite(); var uc:UIComponent = new UIComponent(); uc.addChild(sp); addChild(uc); }