1 Reply Latest reply on Oct 27, 2012 4:20 PM by jg716

    AIR for desktop and multiple swfs

    jbach2 Level 1

      I know when packaging AIR for mobile devices, you can load external swfs as long as they contain no code, but I was wondering if the same limitation exists for AIR on the desktop.

      Building a kiosk application and would like to organize and load the various 'views' similar to how I would create and organize a flash based web application.

        • 1. Re: AIR for desktop and multiple swfs
          jg716 Level 1

          Hi jbach...


          In AIR for desktop, you can definitely load external swfs and they can contain code (works on Android also).


          There's a in-depth discussion of how to accomplish this here:


          http://blogs.adobe.com/cantrell/archives/2010/03/extending_air_applications_with_plugins.h tml


          This article talks about security considerations, etc - and is worth understanding.


          However, if you want to just test it out without worrying about security:


          var stream:FileStream = new FileStream();  
          stream.open(_file, FileMode.READ);


          var bytes:ByteArray = new ByteArray();


          var context:LoaderContext = new LoaderContext();
          context.allowCodeImport = true;


          var loader:Loader = new Loader();
          loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadHandler);
          loader.loadBytes(bytes, context);


          function loadHandler(e:Event):void
          _content = DisplayObject(e.target.content);


          So basically:

          1. Read the file as a byte array.
          2. Create a loader context and set allowCodeImport to true.
          3. Create a loader and use loadBytes to "convert" to a useable swf.
          4. On complete, e.target.content contains your swf (fully accessible with code, etc.)


          Hope this helps!  Good luck with your application.