[web] Loading a flex app into another flex app

Started by
0 comments, last by Black Knight 13 years, 7 months ago
Hi guys this is going to be a long post so bare with me :)

I have been working on a flex application and I want to load other flex applications into this app. I have nearly tried everything on the adobe docs and on the web and nothing seems to work. The strange thing is the load method seems to load the application itself into self. So I have App1.swf and App2.swf. App1.swf tries to load App2.swf and add it to a panel in the gui but for some reason instead of App2.swf it loads itself.

Here is the code for the two simple apps that produce the issue. First the code for the app that I try to load.

<?xml version="1.0"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" height="200" width="200">        <mx:Label text="I am here."/>	<mx:Box width="50" height="50" backgroundColor="#ff0000"></mx:Box></mx:Application>"App2"


As you can see it's just a simple flex app with a label and box, single mxml file.

Here is the app that tries to load it:

"App1"
<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">			<mx:Panel id="panel1" title="baws" width="500" height="400"></mx:Panel>		<mx:Button label="load external swf" click="loadgame(event)"></mx:Button>		<mx:Script>		<![CDATA[		import flash.display.DisplayObject;		import flash.display.Loader;		import flash.events.Event;		import flash.net.URLRequest;		import flash.events.MouseEvent;		import mx.controls.SWFLoader;		import mx.core.UIComponent;					import mx.managers.SystemManager;        		import mx.controls.Label;                            public var loader:Loader;  		public function handleInit(event:Event):void  		{  			 var myComp:UIComponent = new UIComponent();  			 myComp.addChild(event.target.loader.content);  			 panel1.addChild(myComp);  		}  								private function loadgame(e:MouseEvent):void		{			loader = new Loader();  			loader.contentLoaderInfo.addEventListener(Event.INIT, handleInit);  			loader.load(new URLRequest('flexapp.swf'));  		}						]]>	</mx:Script>	</mx:Application>


When ran this loads App1 into the panel inside App1 basically it loads itself into itself. I am using FlashDevelop with the Flex SDK.

Anyone got any idea what might be wrong this is driving me nuts for a few days now.
Advertisement
Doh I hate myself.

Turns out it was a name clash, both the App1.swf and App2.swf had Main.mxml as their file and this was resulting in 2 top level classes with name "Main". I renamed one of them to a different name and it worked.

This topic is closed to new replies.

Advertisement