1

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@c513eb9 to mx.core.IUIComponent 

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

Thanks, Sims

Constantiner
  • 14,231
  • 4
  • 27
  • 34
Sims
  • 23
  • 2

3 Answers3

3

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.

Constantiner
  • 14,231
  • 4
  • 27
  • 34
1

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

Dennis Jaamann
  • 3,547
  • 2
  • 23
  • 42
  • Thanks, but it still won't work. I'm getting the errorMessage cannot convert _Main_mx_managers_SystemManager@3ca6eb9 to mx.managers.SystemManager. – Sims May 26 '11 at 09:29
  • Are you sure that you have copy pasted this correctly? When I run this in my Flash builder it works perfectly. – Dennis Jaamann May 26 '11 at 09:37
  • I hope i did so... I'm writing actionscriptCode and not FlexCode if that makes any difference. – Sims May 26 '11 at 09:39
  • Nope that should not make any difference. Because mxml will be converted to generated ActionScript by your compiler. Have a closer look to what is in the example and do it exactly as stated. Works perfectly on my machine... Also, make sure that both your flex applications are compiled with the same SDK, otherwise you will get other error messages as well – Dennis Jaamann May 26 '11 at 09:41
0

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);
  • Thats what im trying now. I want to manipulate some Objects in the loaded application but i dont get over the SystemManger somehow.. Thats my problem now. – Sims May 26 '11 at 11:45