2 Replies Latest reply on Apr 7, 2009 3:17 AM by eprevot

    Access loaded SWF in a different ApplicationDomain


      Here is a code that works when the two applications are in the same applicationDomain.

      I load a swf file with SWFLoader from a main application, and I use a different applicationDomain :


      var loader:LoaderContext = new LoaderContext();

      loader.applicationDomain = new ApplicationDomain();

      swfloader.loaderContext = loader;

      swfloader.addEventListener(Event.COMPLETE, handleSwfLoaderComplete);



      now I want to access the loaded application (for example, to listen when the loaded application is completed or access its method) :


      var app:SystemManager = SystemManager(swfloader.content);


      This results in an error on this last line :

      Error #1034: Type Coercion failed: cannot convert _LoadedSWF_mx_managers_SystemManager@-6e9aaddf to mx.managers.SystemManager

      Again, this code works if the main application and the loaded application are in the same applicationDomain, and through debugging it appears the casted data (swfloader.content) is the same class _LoadedSWF_mx_managers_SystemManager but no error...


      Does anybody have an idea ?

        • 1. Re: Access loaded SWF in a different ApplicationDomain

          Hi eprevot, this to do with application domain sandboxing to prevent malicious code from excuting with the same authority as the host application. I would suggest you have a read through The Marshall Plan as this should provide you with the answer you are looking for.


          http://butterfliesandbugs.wordpress.com/2008/08/18/the-magic-of-the-marshall-plan/ (a brief overview of the actual process)


          http://opensource.adobe.com/wiki/display/flexsdk/Marshall+Plan (the actual "plan")






          Mike Jones


          Adobe Community Expert For Flex
          Adobe Certified Expert for Flex 3 & AIR
          w./ www.flashgen.com

          b./ blog.flashgen.com


          Catch Me At


          Scotch on the Rocks London '09
          Flash on the Beach Brighton '09
          Author Of Developing Flex Components
          Addison-Wesley (Q4 / 2009)

          • 2. Re: Access loaded SWF in a different ApplicationDomain
            eprevot Level 1

            ok the problem is : swfloader.content is the SystemManager of my sub-application, so I can't cast it to the SystemManager of my main application which is in another applicationDomain.


            But how can I get a reference to my loaded application ?

            SystemManager(swfloader.content).application will throw the cast error, and swfloader.content.application will not compile.


            Can I access the sibling application's SystemManager ?