2 Replies Latest reply on Jun 17, 2011 7:35 PM by drkstr_1

    Can I load xml file from SWC without using @embed

    eckhoff_randy Level 1

      I'm developing a mobile application in which I need to load xml files from File.applicationDirectory. This works great if the xml files are part of the main application swf. But I would like to move these xml files into a SWC so they could be shared across multiple applications.

       

      Using FlashBuilder 4.5, when a SWC is built, I can specify files to embed in the library that are not assets (Assets Tab of Flex Library Build Path). For various design reasons, I do NOT want to embed the xml files via @embed.

       

      When the swc is built and I open it up using a zip utility, I see the xml files in there just fine. So they are being bundled with the SWC. But how can I load these files in my main application that does not involve using @embed? When the main application is built, the swc setting for link type is "merged into code".

       

      I wouldn't expect the application to automatically pull out the xml files from the swc and place them in the File.applicationDirectory on the mobile device. I've tried loading from there just in case but file.exists is false (as expected).

       

      I've searched the web (and continue to do so) and all the answers seem to be to use @embed. Is there another way?

       

      Randy

        • 1. Re: Can I load xml file from SWC without using @embed
          Peter Blazejewicz Level 4

          Hi Randy,

           

          you could instead simply create "assets" directory on your local network (somewhere) and then use "Import" > "Advanced" linking feature in Flash Builder to add linked assets folder to each of your project. it *will* be included automatically in application build preferences and within "Package Contents" (available later under app directory). This is common way to share assets accross different Eclipse projects (I believe it will work as drag&drop feature on Windows by dragging folder into open project in Eclipse - but on OS X it simply does not work that way as directory is simply copied into new project instead of asking for linkage option - so File>Import menu should be used).

          This is long, established feature of Eclipse IDE, see e.g.:

          http://www.russellbeattie.com/blog/1002305

           

          regards,

          Peter

          • 2. Re: Can I load xml file from SWC without using @embed
            drkstr_1 Level 4

            It's actually a lot easier than you think.

             

            Just reference the file like any'ol URL using a path relative to the SWC's src directory.

             

            So if you include the file "assets/xml/some.xml", just use that same string like you would any remote resource.

             

            For example:

             

            var loader:URLLoader = new URLLoader( new URLRequest("assets/xml/some.xml"));

             

             

            I believe it would also work like this "/assets/xml/some.xml", but I prefer relative paths so the link doesnt break if moved out of the SWC...