Flex: Embedding an external asset

Wow, this is one of these things that really breaked my head.
I was reading a tutorial about how to embed an icon on an Alert box you can find it here btw ;)
[FlexExamples.com - Setting an Icon in an Alert Control]

As you see the image is being embedded with

1
2
3
4
// Embed the error.png image.
			[Bindable]
			[Embed(source='assets/error.png')]
			private var Icon:Class;

Somehow my Flex environment constantly throws an error telling me “Unable to resolve ‘assets/error.png’ for transcoding”
Well.. that’s weird, I have my flex project pretty clean and tidy, I also check for upper/lower case, where I’m definately bad at..

After a while moving images, re-writing slashes I came up with the conclusion that as soon as you embed an image into your flex app and the image is located in a folder you need to start with a slash before the folder name.

eg. You have an image located on \assets\error.png you need to call it up with following code

1
[Embed(source='/assets/error.png')]

Just wanted to share this with you guys, since it’s not very obvious in my eyes..

Have a good one
Tiago

Creative Commons License
The Flex: Embedding an external asset by Tiago's Weblog, unless otherwise expressly stated, is licensed under a Creative Commons Attribution 2.5 Switzerland License.
Leave a comment

6 Comments.

  1. Thanks. Solved a problem of hours of frustration

  2. No problem, happy that I coudl help you

  3. I am facing an issue with image embeding..
    here is the scenario..
    i have a bunch of images in a folder inside flex project calles “assets”

    in the mxml file, i had created an xml data model..
    and when i try to set the image source ( same mxml file) using embed image,
    i am unable to display the image. i am new to flex and dont know as to wher
    i can chk for the debug information. i had literally tried what as i can with the
    embed syntax. please help.

    best regards,
    Rupesh

  4. Thanks man it works fine now

  5. @Rupesh

    Did you resolve this, I’m having the very same issue – and it is killing my brain.

    Please shed some light

  6. hi,

    In my case, I like to embed a image(gif) from the source of ‘URLRequest’ how to achieve this.. Iam using a GIFplayer to load the gif file.

    My code is..

    myGIFPlayer.load(new URLRequest(‘loader-indicatorBig3.gif’));

Leave a Reply

Your email address will not be published.


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">