8 Replies Latest reply on Aug 12, 2010 2:21 PM by thilgen

    Flash AS3 Loader URLs

    davedev066 Level 1

      I have an application I am converting from Flash AS3 that uses the Loader class to load swfs and other files. It is currently using relative paths like "../swfs/game.swf", but these give a URL not found error when run in AIR 1.5. How should the paths be configured for AIR? Is there a way I could do modify the loading with minimal changes to code? There's a lot of paths that would need to be changed and tested.

        • 1. Re: Flash AS3 Loader URLs
          thilgen Level 4

          Check out File.applicationDirectory to access content located in your AIR application directory.

           

          Something like this usually does the trick:

           

          var mySWF:File = File.applicationDirectory.resolvePath("swfs/my.swf")

           

          Hope that helps.

           

          Chris Thilgen

          AIR Engineering

          • 2. Re: Flash AS3 Loader URLs
            davedev066 Level 1

            Thanks for the response. Why doesn't the Loader class work? Just curious. It be good from the standpoint of being able to develop one set of code that works on the web and in AIR. Also, the AS3 documentation says the Loader class its supported by AIR runtime.

            • 3. Re: Flash AS3 Loader URLs
              zeroskillz Level 3

              It does, it's a matter of figuring out where the realative path points to with AIR -- which I believe becomes c:/program files/[yourapp]/swfs/my.swf

              which is also known as File.applicationDirectory.resolvePath("swfs/my.swf") per Chris...

               

               

              Tyr installing your app, then placing the folder of swfs in the app folder (like c:/program files/[yourapp]/swfs/my.swf)

               

               

              HTH

              -Ted

              • 4. Re: Flash AS3 Loader URLs
                davedev066 Level 1

                Oh. Sorry. Your response reminded me of an import detail. The paths fail to link ONLY in Test Movie. When I build and run the application, they link fine. In test movie, they give me a url not found error.

                • 5. Re: Flash AS3 Loader URLs
                  zeroskillz Level 3

                  ah, I think the path for the swfs is local to the .fla then...

                  • 6. Re: Flash AS3 Loader URLs
                    chris.campbell Adobe Employee

                    Moved to the Adobe AIR Development forum

                    • 7. Re: Flash AS3 Loader URLs
                      davedev066 Level 1

                      Okay. So I don't know if this is what people have been saying, but I found a solution. I previously had

                       

                      project/shell/shell.swf

                      project/swfs/game.swf

                       

                      then from shell running in the Flash player with test movie I could use "../swfs/game.swf" to load the game swf.

                       

                      When running in AIR and test movie in Flash, I have to move the swfs folder to the shell folder like this

                       

                      project/shell/swfs/game.swf

                       

                      The AIR test movie will then successfully link to the game.swf. Maybe its ignoring the ".." of my original path?

                      • 8. Re: Flash AS3 Loader URLs
                        thilgen Level 4

                        I believe we tend to encourage AIR developers to not make use of hand-coded relative paths - and to instead rely on these routines

                         

                          File.applicationDirectory.resolvePath()
                          File.applicationStorageDirectory.resolvePath()
                          File.desktopDirectory.resolvePath()
                          File.documentsDirectory.resolvePath()
                          File.userDirectory.resolvePath()

                          File.parent

                         

                        Also, and I apologize I can't seem to find it in the docs right now, but I believe AIR also imposes rules on File.resolvePath("..") and File.parent that disallow traversing up the file directory hierarchy above the root of the installed application.

                         

                        You can of course work around this by manually constructing a File like this:

                         

                          var rootDir:File = File.applicationDirectory;
                          trace(rootDir.nativePath); // C:\Documents and Settings\cthilgen\Desktop\p-test-as-clean\bin-debug
                          var rootDirParentBad:File = rootDir.parent;
                          trace(rootDirParentBad); // rootDir.parent is null - can't rise above app root folder
                          var rootDirParentGood:File = new File( rootDir.nativePath + "/.." );
                          trace(rootDirParentGood.nativePath); // C:\Documents and Settings\cthilgen\Desktop\p-test-as-clean

                         

                        Hope this helps.

                         

                        Chris Thilgen

                        AIR Engineering