5 Replies Latest reply on Sep 17, 2010 1:43 PM by Flex harUI

    Type Coercion In SandBox Configuration

    fatima.m Level 1

      Hi,

       

      I've setup a Sandbox configuration.  While loading SwfFile into a sandbox i attemp to access the SystemManager class of the loaded application.

       

      I've defined the bootstrap to include SystemManager as follows:

       

      import mx.managers.SystemManager; SystemManager;

       

      My understanding is that since the bootstrap loads the main portal application into a child domain that all application domains created by main portal application inherit the definitions of the bootstrap.

       

      But when i run the code i get a type coercion error stating that the SystemManager class defined in the application being loaded is not the same as the SystemManager class in the portal application.

       

      TypeError: Error #1034: Type Coercion failed: cannot convert _loadedApp_mx_managers_SystemManager@601a1e9 to mx.managers.SystemManager.

       

      Am i missing something?

        • 1. Re: Type Coercion In SandBox Configuration
          Flex harUI Adobe Employee

          My guess is that loadedApp.swf is not being loaded into a child appdomain of

          the bootstrap.  IIRC, you can't use loadForCompatibility=true, you have to

          specify your own LoaderContext.

          • 2. Re: Type Coercion In SandBox Configuration
            fatima.m Level 1

            Here is how i'm loading the swf file.  Am i missing something? 

             

            loaderContext.securityDomain = SecurityDomain.currentDomain;

            loaderContext.applicationDomain = new ApplicationDomain();

             

            var swfLoader:SWFLoader = new SWFLoader();

            swfLoader.autoLoad = true;

            swfLoader.loaderContext = loaderContex;

            swfLoader.percentHeight = 100;

            swfLoader.percentWidth = 100;

            swfLoader.cachePolicy = UIComponentCachePolicy.OFF;

            • 3. Re: Type Coercion In SandBox Configuration
              Flex harUI Adobe Employee

              Yes, you will need the applicationDomain of the bootstrap and use:

               

                  loaderContext.applicationDomain = new ApplicationDomain(bootstrapAppDom)

              • 4. Re: Type Coercion In SandBox Configuration
                fatima.m Level 1

                Thank you this makes sense.

                 

                I retrieve the bootStrapLoader App Domain as follows:

                 

                var bootStrapAppDomain:ApplicationDomain = ApplicationDomain.currentDomain.parentDomain;

                var loaderContext:LoaderContext = new LoaderContext();

                loaderContext.securityDomain = SecurityDomain.currentDomain;

                loaderContext.applicationDomain = new ApplicationDomain(bootStrapAppDomain);

                var swfLoader:SWFLoader = new SWFLoader();

                swfLoader.autoLoad = true;

                swfLoader.loaderContext = loaderContext;

                swfLoader.percentHeight = 100;

                swfLoader.percentWidth = 100;

                swfLoader.cachePolicy = UIComponentCachePolicy.OFF;

                 

                Now i get the following error:

                 

                Type Coercion failed: cannot convert mx.managers::LayoutManager@9467f31 to mx.managers.ILayoutManager

                 

                I added both LayoutManager and ILayoutManager to boostrap but error still exists.

                 

                Am I retrieving bootstrap Application domain correctly?

                • 5. Re: Type Coercion In SandBox Configuration
                  Flex harUI Adobe Employee

                  Using currentDomain.parentDomain isn't guaranteed to work in all scenarios,

                  but it sounds like it is working for you.  Now you are running into the

                  problem that, once you share something like SystemManager, you share its

                  dependencies and singletons and the singletons will likely be incompatible.

                   

                  You can keep adding stuff to the bootstrap, but you are effectively

                  neutering any advantage of sandboxing.  You want to share as little as

                  possible, or just give up and share everything.

                   

                  Instead of trying to access the sub-app as SystemManager, you can try just

                  sharing and accessing it via ISystemManager, although even ISystemManager

                  has dependencies and version compatibility issues.

                   

                  Depending on what you want from the sub-app, you might find a better common

                  class like IEventDispatcher if you just want to call addEventListener.  Or

                  you'll just have to deal with it as an untyped object.