0 Replies Latest reply on Oct 14, 2009 9:37 AM by emansouri

    SWFLoader Problems

    emansouri Level 1

      I have a major application that involves a Flex application acting as a main container, and it loads loads other Flex applications into it via SWFLoader.


      Originally, the main container was built in Flex 3 and I was loading Flex 4 child applications into it.  This was working fine until the Flash Builder Beta 2 came out.  So I decided I am going to port my main container from Flex 3 to the Flash Builder Beta 2 and I am having all sorts of problems with the SWFLoader implementation.


      I want to have two different configurations for the SWF content to load into the SWFLoader.


      The first configuration should be totally sandboxed such that the only way that the child SWF can communicate with any other SWF is via LocalConnection.


      The second configuration should be such that individual child SWFs are in sibling ApplicationDomains so they can have their own Singletons of the same name, but, content needs to be able to be dragged and dropped from one child SWF to another child SWF.  For instance, the child SWFs will often have AdvancedDataGrid implementations and they'll often need to be able to have content dragged from one to the other.


      I currently have a SWFLoaderFactory class that has a static method as such:


              public static function getSWFLoader(sandbox:Boolean=true):SWFLoader
                  // create the SWFLoader instance
                  var swfLoader:SWFLoader = new SWFLoader();


                  // not sandboxed
                      swfLoader.loadForCompatibility = true;
                  // sandboxed
                      var context:LoaderContext = new LoaderContext();
                      context.securityDomain = SecurityDomain.currentDomain;
                      context.applicationDomain = new ApplicationDomain();
                      swfLoader.loaderContext = context;               
                  // return the SWFLoader instance
                  return swfLoader;


      This was working exactly as I needed it to when the main container was in Flex 3 but now in Flex 4 it is broken.


      What happens is with the swfLoader.loadForCompatbility set to true, the following error occurs:


      TypeError: Error #1009: Cannot access a property or method of a null object reference.
          at mx.controls::SWFLoader/initSystemManagerCompleteEventHandler()[E:\dev\gumbo_beta2\framewo rks\projects\framework\src\mx\controls\SWFLoader.as:2466]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.managers::SystemManager/initHandler()[E:\dev\beta1\frameworks\projects\framework\src\m x\managers\SystemManager.as:3197]


      I'll add that the child SWFs will always be on a different domain than the parent SWF container.


      I would appreciate it if someone could help me solve this problem once and for all and create the optimum configuration that will allow me to do what I want to do.