Embedding assets with ResourceBundle

Here’s a quick tip you won’t find easily on live docs…

Yesterday I found myself needing to embed assets in a .properties file (ResourceBundle) however after looking through the Flex documentation I wasn’t completely satisfied with the examples that were available. So I tried something pretty simple and it works perfectly.

To embed an external asset such as an image, audio file, font etc you need only specify an embed directive just as one normally would for an asset, and the file will be embedded in the application. This approach is very much like using the embed directive to embed assets in CSS but only with properties files instead.

For example, suppose you wanted to embed an image named, “image.jpg” using a properties file. To do so simply define the image as follows:

Then to display the embedded image simply reference the class object to which it has been embedded as follows:

And that’s it. Same applies for all embedded assets. I also provided a quick example as well – complete with my son Anthony on the Piano!.

{ 4 comments to read ... please submit one more! }

  1. Nice solution. However, it’s not immediately clear to me what the benefits of doing this are. Can you elaborate?

  2. Waoh that’s neat ! Funny how there can be tons of undocumented / misdocumented features like that in the Flex framework…

    Thanks for sharing,

    {Maz}

  3. Hey Ted,

    The benefits of this solution are many; with localization / externalization of all embedded assets such as images, fonts, audio files etc being the most significant.

    Best,
    Eric

  4. Have you tried compiling your application using the command line compiler? In my case it doesn’t seem to be able to find the assets that should be embedded…

{ 0 Pingbacks/Trackbacks }