public override function addChild(child:DisplayObject):DisplayObject
虽然参数child的类型是DisplayObject,但是它必须实现IUIComponent接口(所有Flex组件都实现了这一接口),才能添加。 如果要在Application里添加Sprite,可以先把它装进一个UIComponent,然后再添加这个UIComponent: 官方的说法: * <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> 例子:
复制代码 代码如下:
import mx.core.UIComponent;private function init():void { var sp:Sprite = new Sprite(); var uc:UIComponent = new UIComponent(); uc.addChild(sp); addChild(uc); }