2 Replies Latest reply on Dec 19, 2011 11:28 AM by jjtaylor06

    How to load content from the application directory?

    jjtaylor06 Level 1

      I'm currently working on an AIR desktop application that will be distributed on OSX and Windows. The main applicaiton SWF will load a child swf that has been packaged. When I've attempted to load the child SWF via loader.load() with a URI of "app:\\TheChildContentSWF.swf", the load has failed with an IOError. If I force a copy of the the SWF (in OSX) to the MacOS directory where the executable resides, the child SWF would load. I was a little stumped by this so I decided to check what the nativePath of the application directory was via File.applicationDirectory.nativePath (it turned out to point at the Resources directory). Does the "app://" URI point to different paths when using Loader vs File?

       

      If so, is there a way to package content so that it is installed in a directory that Loader can recognize without hitting security sandbox issues?

       

      Visual of the OSX app directory structure (simplified)

       

      MyApp.app\

           Contents\

                Frameworks\

                MacOS\

                     executable

                Resources\

                     TheAppSWF.swf

                     TheChildContentSWF.swf

                      ... // other content

       

      Thanks for any help!

       

      Josh

        • 1. Re: How to load content from the application directory?
          DonMitchinson

          When loading application, move the swf to the applicationStorage folder if it doesn't exist already.

           

          Something like ...

          private var swfDistribute:File = File.applicationDirectory.resolvePath('ResourcesChildContentSWF.swf');
          private var swfLocal:File      = File.applicationStorageDirectory.resolvePath('TheChildContentSWF.swf');
          
          private function onCreationComplete():void 
          {
             if (!swfLocal.exists) {
                if (swfDistribute.exists) {
                   swfDistribute.copyTo(swfLocal);
                }
             }
          }
          
          

          Then you should be able to call your loader.load() URI with the variable (swfLocal)

          1 person found this helpful
          • 2. Re: How to load content from the application directory?
            jjtaylor06 Level 1

            I ended up resolving the path of the ChildContentSWF.swf in the application directory and checking the uri, e.g.

             

                 var childContent:File = File.applicationDirectory.resolvePath('ChildContentSWF.swf');

                 trace(childContent.uri);

             

            This resulted in 'app://ChildContentSWF.swf' so I believe I was attempting to load via an incorrect URI format.