13 Replies Latest reply on Jun 3, 2009 11:46 AM by DTALA

    Flex/AIR Embed() Differences

    trivinci Level 1

      I have a Flex application that I'm trying to compile to AIR (see post http://forums.adobe.com/thread/419487?tstart=0).  In my Flex app, I embed images like so...

       

          <mx:Style>       
              .commonButton
              {
                  up-skin:            Embed("/assets/max_up.png");
                  over-skin:          Embed("/assets/max_over.png");
                  down-skin:          Embed("/assets/max_up.png");
              }
          </mx:Style>

       

      This works fine in Flex.  Using the same directory structure (assets as a subdirectory to src), the AIR compiler throws errors like this...

       

          Invalid Embed directive in stylesheet - can't resolve source 'Embed("/assets/max_up.png")'.
         
      Why would this syntax and structure work fine in compiling Flex, and fail when compiling AIR?

      More importantly, is there a work-around?

       

          -tri

        • 1. Re: Flex/AIR Embed() Differences
          Gregory Lafrance Level 6

          Not sure why this is happening, but try to omit the beginning forward slash and see what happens. Also, try to do that and also replace the forward slashes with backward slashes.

           

          One other idea is that you may need to have the paths relate to some AIR specific path paradigm, such as this:

           

          import flash.filesystem.File;
          
          var tempFiles:File = File.applicationStorageDirectory;
          tempFiles = tempFiles.resolvePath("images/");
          trace(tempFiles.url); // app-storage:/images
          

          or this:

           

          import flash.filesystem.File;
          
          var directory:File = File.documentsDirectory;
          directory = directory.resolvePath("AIR Test");
          
          File.createDirectory(directory);
          trace(directory.exists); // true
          
          • 2. Re: Flex/AIR Embed() Differences
            trivinci Level 1

            Greg,

             

            Thanks for the quick response!  I tried playing with the slashes with no luck.

             

            Also, I don't see how to apply the file system function calls to my css; I'm probably missing something silly there.  Problem is, seems that approach would diverge my Flex and AIR solutions.  That would be a bad thing since I'm trying to use the same code for both my Flex and AIR deployments.

             

                -tri

            • 3. Re: Flex/AIR Embed() Differences
              Gregory Lafrance Level 6

              The file system calls would be done in ActionScript, not in CSS.

               

              If this post answers your question of helps, please mark it as such.

              • 4. Re: Flex/AIR Embed() Differences
                trivinci Level 1

                Thanks for hangin' in there with me on this.

                 

                Sure, file system calls are done in AS, which is why I'm wondering how they apply to styles.

                 

                Also, any use of file system calls would keep my Flex app from compiling.

                • 5. Re: Flex/AIR Embed() Differences
                  Gregory Lafrance Level 6

                  I'm wondering if the file system calls are necessary to resolve file paths in an AIR app.

                   

                  You are right, those system calls won't work in a Flex app, but you're trying to port to AIR, right?

                  • 6. Re: Flex/AIR Embed() Differences
                    trivinci Level 1

                    The preferred deployment is Flex.  However, I also need to provide an out-of-browser experience (some users are subject to a "disable Flash in your browser" security policy).

                     

                    So, this isn't a one-way porting effort.  I need to maintain both a Flex and an AIR version of the same application.

                    • 7. Re: Flex/AIR Embed() Differences
                      Gregory Lafrance Level 6

                      Well, considering the fact that the root tag of an AIR app is <mx:WindowedApplication> and the root of Flex is <mx:Application> that may be difficult. But perhaps you are maintaining two main app pages, and trying to keep the rest the same. In that case this may be another page that must be different.

                      • 8. Re: Flex/AIR Embed() Differences
                        trivinci Level 1

                        Correct.  I have two main pages that create a canvas and programmatically populate that canvas.  I do this type of embedding in much more complex classes and custom components.  Surely, the syntax for embedding images doesn't differ between Flex and AIR.  I laid things out with the assumption there are no differences like this (the same facility needs to be used differently).

                         

                        I hoped I was just making a nooB mistake.  Looks like I've got a bit of restructuring to do.  I suppose I could create/play with a sample mini-app just to test it out.

                         

                         

                        • 9. Re: Flex/AIR Embed() Differences
                          trivinci Level 1

                          Hi Greg,

                           

                          I think I see where you were going with the File function calls.  See where AIR is looking for the assets directory, then adjust my Embed path or directory structure to match.

                           

                          Well, I took your File function call suggestions, spun up a simple AIR app, and determined where AIR is looking.  Applying that to my app didn't help.

                           

                          I then realized that these calls would show the runtime location, but I'm having problems compiling.  As I understand it, the Embed() directive puts the image in the swf, so there's no file system reference to get those images at runtime.  It also means that I need to give Embed() a compile-time location for the files.

                           

                          So, my next attempt was to simply give a fully-qualified path to Embed().  But of course, no luck there either.

                           


                          General cry for help:
                          Has anyone successfully embedded an image in an AIR application through a stylesheet Embed() directive?  If so, could you post the Embed() syntax you used and specify where you keep your images in your AIR workspace?

                           

                              -tri

                          • 10. Re: Flex/AIR Embed() Differences
                            trivinci Level 1

                            OMG!  I finally found a post here (http://kyledodge.org/?cat=5&paged=2) making reference to a similar problem.  In his case, a typo in one (1) file path caused the Flex compiler to flag all 160 of his Embed() directives as invalid.

                             

                            In my case, one file was not copied over from my Flex build environment.  When compiling for AIR, all of my Embed() directives were flagged as invalid because of that one file.  Once I restored it, I got a clean compile for everything.


                            This seems like a compiler bug to me... sort of like saying all of your classes are whacked because of a typo in one.  However, I'm still a nooB in this area so I'll take it as a lesson learned.

                             

                             

                            • 11. Re: Flex/AIR Embed() Differences
                              DTALA Level 1

                              Hi Trivinic.

                              I read your posting with the great interest, as i am a noob as well and have come across a situation somewhat your (see below):

                               

                              I have a question related to the type of thing that u r doing. Suppose I have three .swf files (call them game1.swf, game2.swf, game3.swf) . In my AIR app (running in the desktop mode, NOT via browser), I want have three buttons (assocaited with the three game.swf files), whereby when my AIR app comes up the  user can click on a button which would in turn invoke one of the three games:

                               

                              Questions:

                              1. I am assuming that I can use Embed() the same way u r  and have the game.swf files in assets directory.

                              - Any idea if this would work?

                              - if my AIR app (called it foo.air) is stored in c:\myApps\foo.air, where should i put my game.swf files so i won't get AIR security violation at the run time?

                               

                              2. A totally unrelated question: suppose in my AIR app, I want to read a .txt file  via a system/lib call.

                              - Any info about how to make a sys/lib call from with AIR?

                              - Due to AIR security mode, do i need to worry about the location of the filw, i.e., does the local .txt file MUST be in the directory/folder as the AIR bits thmselves?

                               

                              Thx in advance for your help.

                              DTALA

                              • 12. Re: Flex/AIR Embed() Differences
                                trivinci Level 1

                                DTALA,

                                 

                                Sorry to disappoint, but what you're attempting is a bit more advanced than anything I've ever tried.

                                 

                                Re: Embed()ing swf files
                                I have no idea if this would work.  Adding movies is out of scope for my project.  Flash (Flex) libraries would be added via SWC files.

                                 

                                Re: reading a file from the file system
                                I followed this tutorial to get me going.

                                 

                                http://learnola.com/2008/11/10/beginners-adobe-air-tutorial-part-2/

                                 

                                     -tri

                                • 13. Re: Flex/AIR Embed() Differences
                                  DTALA Level 1

                                  Hey Tri,

                                  Thx 4 getting back 2 me. Appreciate responding to my email.

                                  DTALA