开发者

can't add Application to displaylist

I'm trying to use a SWFLoader to load an Application and add the loaded Application to my Displaylist.

public function onComplete(e:Event):void {
    someContainer.addChild((e.target.content));
}

//somewhere in main
var loader: SWFLoader = new SWFLoader();
loader.addEventListener(Event.COMPLETE, onComplete);
loader.load(urlToSwf);

I'm getting the errormessage

cannot convert _Main_mx_managers_SystemManager@开发者_Go百科c513eb9 to mx.core.IUIComponent 

Could anybody tell me why this won't work or how i can fix this?

Thanks, Sims


First of all, I'm not recommend you to load Flex applications into another Flex applications. There are ready to use Modules present in Flex framework. You can read more details here.

What about your case in particular you should read addChild() documentation:

Note: While the child 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.

So you can add UIComponent first and the add your system manager there.


The problem occurs because what you are trying to add to stage is of type SystemManager and of course you want to add your application to the display list.

So try this:

<mx:Script>
    <![CDATA[
        import mx.events.FlexEvent;
        import mx.managers.SystemManager;

        private var _systemManager:SystemManager;

        protected function onLoaderComplete(event:Event):void
        {
            _systemManager = SystemManager(loader.content);
            _systemManager.addEventListener(FlexEvent.APPLICATION_COMPLETE, onApplicationComplete);
        }

        private function onApplicationComplete(event:FlexEvent):void
        {
            mainContainer.addChild(_systemManager.application);
        }
    ]]>
</mx:Script>

<mx:SWFLoader id="loader" source="main.swf" width="800" height="600" autoLoad="true" complete="onLoaderComplete(event)"/>

<mx:VBox id="mainContainer"/>

Cheers


Just add the SWFLoader to the container.

public function loader_completeHandler(event:Event):void
{
    var loader:SWFLoader = event.target as SWFLoader;
    someContainer.addChild(loader);
}

//somewhere in main
var loader:SWFLoader = new SWFLoader();
loader.addEventListener(Event.COMPLETE, loader_completeHandler);
loader.load(urlToSwf);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜