1 Reply Latest reply on Jul 3, 2013 2:02 PM by Flex harUI

    ApplicationDomain.getDefinition not working in Release Build for iOS

    jaishy

      I am loading an external SWF file and using ApplicationDomain.getdefination("Slide1") in my Flex4.6 using AIR 3.2 for iOS to get the Embed content inside it.

       

      It works fine when I compile in Debug Mode(Fast) but gives Ref Error 1065 (See Error Line* below) on Ipad when compiles in Release Mode(Standard).

       

      Any help/sugestion is appriciated.

       

      The sample code in my actionscript class looks like :-

       

      var request:URLRequest;

      request = new URLRequest(strSwfPath);

       

      var rslLoader:Loader = new Loader();

       

      var appDom:ApplicationDomain = new ApplicationDomain( ApplicationDomain.currentDomain );

       

      var loaderContext:LoaderContext = new LoaderContext(false,appDom);

       

      loaderContext.allowLoadBytesCodeExecution = true;

       

      rslLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadSwfCompleteHandler, false, 0, true);

      rslLoader.load(request, loaderContext);

       

      //--

      private var loadedAppDomain:ApplicationDomain;

      public var embedClass:Class;

      //--

      private function loadSwfCompleteHandler(event:Event):void

      {

           loadedAppDomain = rslLoader.contentLoaderInfo.applicationDomain;

           embedClass = loadedAppDomain.getDefinition(slideName) as Class; >>>>>>>>>>>>>>>>>>>>>>> *Error Line.

      }

       

      //--------------------- The code inside my external SWF looks like:-

       

      package

      {

          import flash.display.Sprite;

      import flashx.textLayout.compose.ISWFContext;

      public class Slide1 extends Sprite implements ISWFContext

          {

              [Embed("slide1/sldBg1.png", mimeType="image/png")]

              public static const bg:Class;

              public function callInContext(fn:Function, thisArg:Object, argsArray:Array, returns:Boolean=true):*{

       

                   if (returns)

       

                           return fn.apply(thisArg, argsArray);

       

                   fn.apply(thisArg, argsArray);

               }

          }

      }

        • 1. Re: ApplicationDomain.getDefinition not working in Release Build for iOS
          Flex harUI Adobe Employee

          By using:

           

          
          var appDom:ApplicationDomain = new ApplicationDomain( ApplicationDomain.currentDomain );
          
          

           

          you are setting up a child application domain, and parents cannot see classes in their children, so the child classes can be later unloaded.  There are at least 3 ways to modify your code, but it depends on what you are trying to accomplish.

           

          Option 1:  You are going to load and unload different copies of SWFs that all contain the same Slide1 definition as the root of the SWF.  In that case, you would force-link Slide1 into the main app, and case the loader's content to Slide1.

           

          Option 2:  You don't need to ever unload the Slide1 SWF and only load one copy.  In that case, you would set the LoaderContext's applicationDomain to ApplicationDomain.currentDomain.

           

          Option 3:  You are going to load and unload SWFs but only one has Slide1 in it so you don't want to force link it.  If there is a common interface then it is best to use that interface instead, but otherwise, you would implement on each external SWF a way to access its application domain, or have it find the class for you.  I see that you have implemented ISWFContext on the external class, so you could use that to call the method getDefinitionByName, or you could implement a separate call in each SWF that does something like:

           

          Public function getMyApplicationDomain():ApplicationDomain { return ApplicationDomain.currentDomain };
          

           

          and call that instead.

           

          Flex builds both mechanisms into the root of every Flex SWF.

           

          -Alex