8 Replies Latest reply on Mar 1, 2009 1:41 AM by marcink

    importing png's from asset.swf into flex

    marcink Level 1
      hi,

      i have an asset.swf, with png's and jpg's inside, witch i try to import into flex.
      in the image properties dialog i assign each image a class: PNGImage and JPGImage, as example...

      now i want to import the images into flex:
      [Embed(source="asset.swf", symbol="JPGImage")]
      [Embed(source="asset.swf", symbol="PNGImage")]

      while there is no problem with the JPGImage, when i try to import PNGImage, i get an error #2136 in flex.
      can't i import png's into flex??

      thanks
        • 1. Re: importing png's from asset.swf into flex
          injpix Level 3
          You can import PNG files in Flex. Do a Clean build. See if that fixes it.
          • 2. importing png's from asset.swf into flex
            marcink Level 1
            @myIP:

            sorry, the previous question was not precise... i know i can import png files into flash.

            but when the png file is in a swf file, and i try to import it form the swf file i get always an error.

            i tried to make a test project with only one png file inside the swf, but still the same...

            edit: event this <mx:Image source="@Embed(source='assets.swf', symbol='Hand')"/> doesnt work...
            • 3. Re: importing png's from asset.swf into flex
              Francisc Level 3
              Firstly check if the Flash symbol name coincides with the one you mentioned in the Embed MetaData tag.

              Secondly, you are embedding, but not assigning the embedded png to any variable.
              You need to have the name of the var typed as Class (always) immediatly following an Embed statement.

              e.g.
              [Embed(source="asset.swf", symbol="JPGImage")]
              private static cont _myEmbeddedJPG:Class;//you can just write private var _myEmbeddedJPG:Class; if you like

              Now you can use that to display the image.
              e.g. <mx:Image source={_myEmbeddedJPG}/>
              • 4. Re: importing png's from asset.swf into flex
                injpix Level 3
                Either your method or marcink's method of embedding an asset will work. Take a look at the following example M*A*S*H:
                mx.controls.Image example

                marcink, I suggested in my previous post to do a clean build. In Flex Builder navigate to "Project>Clean...". I think that perhaps, there may be some caching going on. And you would need to clean your cache. If you are not using Flex Builder and are just using the SDK, then I believe you wouldn't have to worry about this, since it doesn't cache.

                Is this a runtime error?

                ps. I see you're using PureMVC! :P
                • 5. Re: importing png's from asset.swf into flex
                  Francisc Level 3
                  Hey, myIP!

                  You wanted me to see <mx:Image source="@Embed('assets/Nokia_6630.png')"/>?
                  If so, I know you can embed in MXML as well as CSS, but for ActionScript Embedding as marcink uses, you need to declare the Class variable right after the Embed statement. That is what I was trying to point out as possible cause for error. :)
                  • 6. Re: importing png's from asset.swf into flex
                    marcink Level 1
                    @myIP:

                    the examle i different from my case: it imports a png directly with an url. this works fine for me. no problems.
                    my png is inside a swf library file.

                    i did a project clean - import is not working
                    i opened a new project in flex builder, with a new swf file with only one png image inside - import is not working
                    BUT when i put the pngfile into a movieclip, and import that movieclip, it works...

                    @M*A*S*H 4077:
                    i didn't post my working code here, cause it just seems to simple... :)
                    i have two image files inside a swf: one jpg, and one png. i treat both identically. with both, i check the "Export for Actionscript" and "Export in first frame", i give both a unique classname. both extends "flash.display.BitmapData"

                    now, in flex, i try to embed them with the code i posted.
                    • 7. importing png's from asset.swf into flex
                      marcink Level 1
                      ok. now i narrowed it down - and i think its wierd:

                      when the png's compression is set to lossless(png,gif) it works fine
                      but when the compression is set to photo(jpg), it doesnt. the error i get is a compiler error: Error: Error #2136

                      @myIP: yeah, puremvc rocks...
                      • 8. Re: importing png's from asset.swf into flex
                        marcink Level 1
                        :) and asking mr. google (should have done it earlier) i found out, that this bug is already filed at adobe: http://bugs.adobe.com/jira/browse/FP-109