When I set the source property for a SWFLoader this string works fine:
- source=”images/MyFile.swf”
…but this string gives me the above error:
- source=”@Embed(source=’images/MyFile.swf’)”
Why?
I couldn’t easily Google an answer to this, so it may be worthwhile to post what I learned.
I found two causes for this problem. First of all, for some reason you need an additional slash when you use @Embed, like this:
- source=”@Embed(source=’/images/MyFile.swf’)”
Second, the location of the SWF (or GIF, JPEG, PNG or SVG) may need to be different if you’re using @Embed, so that the compiler can find and embed the file at compile time. A copy of the file should be placed in a location relative to the source file that contains the SWFLoader.
Example: In my case I’m placing my SWFLoader in a custom component that is part of a code library. The code library lives in a separate location from the project that’s using the component.
For the non-embed example above I can place MyFile.swf at [MyProject'sMainSourceFolder]/images/MyFile.swf. FlexBuilder copies it to [MyProject'sOutputFolder]/images/MyFile.swf and the SWFLoader finds it there at run time.
But when I use @Embed, when the compiler sets about embedding the file it expects to find a copy at [MyLibrary'sOutputFolder]/images/MyFile.swf.
HTH
Update: Just found some info in on this in the docs, here:
September 7th, 2007 at 10:16 am
Thanks so much for the tip. This problem was going to drive me up the wall. Thanks!!! I wonder why that extra / needs to be there. Also it might be worthwhile to note for programmers like me whose IT department are security crazy: you can’t link to fonts that you as a user can’t actually touch.
October 11th, 2007 at 6:16 pm
I have the same problem, but which folder should the images be stored. I tried the bin the folder, but Flex is still not displaying the images. Any one, any help will be appreciated if you can help me solve this issue that I am having.
November 9th, 2007 at 4:32 pm
Bless you! This was driving me crazy.
January 5th, 2008 at 11:59 am
I have the same problem as Howard. I can’t get the images to display. Any ideas?
March 14th, 2008 at 8:03 am
Hi all,
I have this problem with the flex ant task.
I’m trying to compile a project. I use @Embed(source=’../assets/first.png’) and the problem is that the compiler does not find it.
PS. for displaying the images just use put the path relatively to the resource. As example I’ve created a war and I’ve put my swf files into the root and the rest in different paths.
As struct: /(root of the war)
/res/image.gif
/test.swf // -> path to /res/image.gif
/WEB-INF/web.xml // for war
April 6th, 2008 at 11:57 am
Was having the same problem!
Your help solved it!!
thnx man!
April 18th, 2008 at 7:11 am
Thanks for the tip – saved a lot of frustration!
May 7th, 2008 at 2:45 am
I have same problem, mainly the complier can not find out path of image,so I put image copy to file which import this image where in dir. In .as file
Embed(source=’MyFile.png’) It’s OK.
October 17th, 2008 at 1:58 pm
Adobe needs to FIX this and make it function better. If you want to put your source in a “src” folder, this basically screws you. Assets should be placed in a special folder, ex. “assets”? Not wherever the files that need to access them happen to be, and not /src/assets. Dropping the assets into the same folder as the class referencing them is no answer either, what if two classes in different folders need to access the same asset? Lame…
April 15th, 2009 at 6:41 am
Try using escape char “\” in path. Should work.
[code][Embed(source="C:\\WINDOWS\\Fonts\\arial.TTF", fontFamily="DaEmbeddedFont", mimeType="application/x-font")][/code]
May 12th, 2009 at 9:29 am
Thanks!!! You saved my life
Was trying to figure out what went wrong…
August 13th, 2009 at 1:10 pm
This link saved me what could have been many hours of research and frustration!!! thanks!
November 12th, 2009 at 4:29 pm
Very helpful.
Just an additional clarification. Your suggestion also applies when embedding an image like this example:
[Embed(source="/images/filter.png")]
[Bindable]
public var filterOffImage:Class;
March 10th, 2010 at 2:58 pm
Thanks so much for this post. Was pulling my hair out and all I really needed was a slash.
I was using an image like Thomas so just placing a slash in front fixed the problem.
[Bindable]
[Embed(source="/assets/stop.png")]
private var Icon:Class;
I also had to fix my fonts url in the stylesheet
@font-face {
src: url(assets/fonts/Helvetica.ttf);
fontFamily: “Helvetica”;
advancedAntiAliasing: true;
}