I don't use loaders - I use modules. Here is a quick and dirty example:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="vertical"
     creationComplete="onCreationComplete()">
     <mx:Script>
         <![CDATA[
             private function onCreationComplete():void
             {
                 currentModule.url = "TestModule.swf";
             }
         ]]>
     </mx:Script>
     <mx:VBox width="100%" height="100%" paddingTop="0" paddingBottom="0"
paddingLeft="0" paddingRight="0">
         <mx:ModuleLoader id="currentModule" width="100%" height="100%"/>
     </mx:VBox>
</mx:Application>

TestModule.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml"; layout="vertical">
     <mx:Script>
         <![CDATA[
             import mx.controls.Alert;

             private function onButtonClick(event:MouseEvent):void
             {
                 Alert.okLabel = "I didn't mean to";
                 Alert.buttonWidth = 120;
                 Alert.show("Why did you click this button?");
             }
         ]]>
     </mx:Script>
     <mx:Button label="Don't click this button!"
click="onButtonClick(event)"/>
</mx:Module>


--- In flexcoders@yahoogroups.com, "Mehdi" <elextra...@...> wrote:
>
> I am getting to the conclusion that the following is not supported at
all. (Using flex 3.2 SDK):
> Loading one SWF into another one using 2 different loaderContext. I
tried using the Loader and the SWFLoader (and to some extend the
ModuleLoader)
>
> 1- Build a simple Flex App with a combo box or Alert Message (on click
of a button for instance).  (=="TestCombo.swf")
> 2. Load that SWF (from Step 1) using the Loader in a new application
Domain (as such:
> var request:URLRequest = new URLRequest("TestCombo.swf");
> _loader = new Loader();
>
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,handleModuleLo\
aded);
>
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,handleE\
rror);
>
_loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_E\
RROR,handleError);
> _loader.contentLoaderInfo.addEventListener(Event.UNLOAD,
unloadHandler1);
> var context:LoaderContext =  new LoaderContext();
> context.applicationDomain = new ApplicationDomain();  //  that's KEY!
> _loader.load(request,context);
>
> In the handleModuleLoaded function, I am simply adding the content of
the comboSWF into a vbox
> vbx.rawChildren.addChild(_loader.content);
>
> 3. Attempt to see the content of the combo or click on the button to
see the Alert from the loaded SWF, and you get an exception. (see below)
>
>   TypeError: Error #1009: Cannot access a property or method of a null
object reference.
>   at
mx.managers::SystemManager/addPopupRequestHandler()[C:\autobuild\3.2.0\f\
rameworks\projects\framework\src\mx\managers\SystemManager.as:3604]
>   at flash.events::EventDispatcher/dispatchEventFunction()
>   at flash.events::EventDispatcher/dispatchEvent()
>   at
mx.managers::PopUpManagerImpl/addPopUp()[C:\autobuild\3.2.0\frameworks\p\
rojects\framework\src\mx\managers\PopUpManagerImpl.as:294]
>   at
mx.managers::PopUpManager$/addPopUp()[C:\autobuild\3.2.0\frameworks\proj\
ects\framework\src\mx\managers\PopUpManager.as:169]
>   at
mx.controls::Alert$/show()[C:\autobuild\3.2.0\frameworks\projects\framew\
ork\src\mx\controls\Alert.as:519]
>   at
TestCombo/___TestCombo_Button1_click()[M:\projects\flex-projects\TestCom\
bo\src\TestCombo.mxml:16]
>
> The same code works perfectly fine if you attempt to load the SWF into
the same applicationDomain, but that's totally not acceptable for us
here.
>
> Using the SWFLoader as opposed to the Loader does not even get you
this far. The TestCombo.swf is not even loaded. I get the following
exception when trying to load the module: (basically complaining about
the system Manager being null)
>
>  TypeError: Error #1009: Cannot access a property or method of a null
object reference.
>   at
mx.controls::SWFLoader/initSystemManagerCompleteEventHandler()[C:\autobu\
ild\3.2.0\frameworks\projects\framework\src\mx\controls\SWFLoader.as:217\
4]
>   at flash.events::EventDispatcher/dispatchEventFunction()
>   at flash.events::EventDispatcher/dispatchEvent()
>   at
mx.managers::SystemManager/initHandler()[C:\autobuild\3.2.0\frameworks\p\
rojects\framework\src\mx\managers\SystemManager.as:2862]
>
> Anything would help. I just need to know whether that's possible or
not using flex sdk 3.2.
>
> Cheers.
>

Reply via email to