boostworthyisryantaylor

Cure For The ‘Unable to resolve asset for transcoding’ Compiler Error

Have you ever tried to embed an asset and ended up having mxmlc throw this error at you?

    Error: Unable to resolve 'yourAsset' for transcoding

I ran into this for the first time this evening. I was working on a Flex application and needed to embed a PNG file in one of my classes like so:

ActionScript:
  1. [Embed(source="../assets/images/myImage.png")]
  2. protected var myImage:Class;

No errors detected in the code, so I went ahead and did a debug build via Flex Builder and everything was just fine and dandy. Later on when I went to do a production build via my Ant build file, mxmlc threw that error. I quickly looked over my build file and everything looked fine, so I did a quick search online and didn't find any good solutions to this. Some others had posted about having this issue and resorted to adding their asset directory as a source directory. I wasn't down to do that, so I began experimenting. I finally managed to get it working; here is what did the trick:

ActionScript:
  1. [Embed(source="/../assets/images/myImage.png")]
  2. protected var myImage:Class;

Yep... Simply adding a slash in front of the '..' made all the difference in the world. Pretty incredible. I just thought I'd vent and share that since I know I'm not the only person out there that has been caught up on this.

35 Comments so far

  1. Derek December 18th, 2007 12:50 pm

    I feel your pain. :-) I came across that same thing this summer when I was working on a project. Actually I have a question about embedding SWF files. I have been using Illustrator CS3 to do most of my design work and converting all of the elements into 'symbols' and exporting it as a SWF . Do you know how I might be able to access those symbols without embedding every single one, ie; [Embed(source='myMovie.swf', symbol='mySymbol')]. I am pretty new to AS but I am pretty sure there is a way I can do this. Thanks.

  2. Ryan Taylor December 18th, 2007 4:24 pm

    Hey Derek,

    Once you have done something like this:

    [Embed(source='myMovie.swf')]
    protected var MyMovie:Class;

    Create an instance of the 'MyMovie' class and listen for it's 'Event.INIT' event. Upon your handler for the 'Event.INIT' event being invoked, the assets inside of the 'myMovie' SWF file are now available for use like so:

    var box:MyFlashBox = new MyFlashBox();
    addChild(box);

    Where 'MyFlashBox' is the class that is associated with the library symbol.

    Just make sure that the 'Automatically declare stage instances' checkbox is unchecked in your ActionScript 3.0 Settings.

  3. Derek December 19th, 2007 6:04 pm

    Thanks for the reply. This works great because I hate using the Flash IDE for design since I have been such a long user of Illustrator and now that it is more integrated with Flash/Flex makes it that much more intuitive for me.

    Thanks again.

    Merry Christmas and Happy New Year!

    Cheers.

  4. bret January 3rd, 2008 10:08 pm

    thanks for posting that man! You're a life saver

    --some random guy

  5. collin January 14th, 2008 1:31 am

    Hey just curious, does "./../myAsset.png" work, that should keep the asset relative to the mxml, and and has been the solution to custom class paths in the flash IDE for my office. Great articles BTW.

  6. Ryan Taylor January 14th, 2008 5:00 am

    Thanks, Collin.

    Correct, that path would check for the asset relative to the location of the class/mxml file rather than the directory the SWF is published to, just like '../myAsset.png' would. The compiler only begins looking for the asset in the SWF file's directory if the first character of the path is '/'.

  7. guille January 21st, 2008 10:24 am

    thanks,
    helped :-)

    guille

  8. daniel April 14th, 2008 7:01 pm

    I have been tearing my hair out over this...
    I've tried placing the image in the same directory as the main mxml file, in a directory containing a component. In a distinct "images" directory in the src, in the component and the "root" directory of the project, even copied and pasted examples from Adobe's own manual.

    All failed.

    And a frustrated hour later, your solution works perfectly :) I'll let you guess at the choice words vented against Adobe, Actionscript and flex builder ;)

    Cheers,
    Daniel

  9. Mark May 5th, 2008 1:11 pm

    Just wanted to thank you (and Google) for the solution.

  10. Mark May 11th, 2008 2:31 pm

    Hey, this was ultra baller. this saved me a ton of trouble.
    Thanks!

  11. correa July 16th, 2008 11:37 am

    Thank you !

  12. Sébastien Ballesté-Antich November 4th, 2008 9:06 am

    +1

  13. Kevin November 18th, 2008 10:41 am

    Another thank you!

  14. Rafael Rinaldi November 20th, 2008 12:16 pm

    Omg, crazy error!

    Thanks.

  15. Alan November 25th, 2008 4:57 am

    +1

    Well done tracking that one down - I was working up to a long session of brain-wracking. Must be something to do with concatenating paths, or similar. Clearly, FB does not use mxmlc internally in the same way.

  16. Dimitri Hautot January 6th, 2009 6:57 am

    Thanks a lot for sharing this!

    Such a simple fix for such an annoying bug...

  17. Mark February 6th, 2009 8:14 pm

    Hi ,

    I am running into the exact issue, except that this time I'm trying to compile a Flex library out of my project using ANT. I am also using the compc executable to create this library.

    The Flex project compiles without any errors in FlexBuilder(version 3.0) , however when I try to automate the build using ANT I get this error :
    Error: Unable to transcode images/icons/vertical_bar_chart_16x16.gif

    Here's how m directory looks like:

    ProjectFolder
    |
    |----build -> Build file located here
    |
    |
    |----com -> location of my source files
    |
    |----images -> location of image artifacts

    I have a package called resources

    package com.sap.xapps.analytics.resources
    {
    [Bindable]
    public class Images
    {
    [Embed(source="images/icons/line_chart_16x16.gif")] public static const iconLineChart : Class;

    }
    }

    Here's what my ANT compilation target looks like:

    Building ${swcFile}

    I get the above mentioned error when I run the ANT script from the build directory.

    I have already tried using (/../images) and even (images/) in the .as file but it hasn't helped. Appreciate if you can suggest any alternatives.

  18. Daemon February 19th, 2009 12:57 pm

    damned... it was that easy !

    Cheers for posting this

  19. Janne February 26th, 2009 5:11 am

    Thanks, this helped!

  20. Fabio February 27th, 2009 7:41 am

    This is what I call a very useful post!
    Thanks for sharing!

  21. Nishant March 10th, 2009 9:59 am

    Thanks !!!!! that saved me a lot of pain.

  22. piecko March 24th, 2009 12:18 pm

    Hi,

    this really saved my day. I spent 2 hours on this annoying bug and the leading slash made it.

    Thank you

  23. Nils Magnus March 30th, 2009 4:53 am

    Thanks! Very useful post!

  24. sarah May 14th, 2009 2:59 pm

    wow. I've never had this happen before. thanks ryan!

  25. Tom C August 25th, 2009 6:46 pm

    Thanks! Saved me a ton of time.

  26. Manu August 28th, 2009 3:27 pm

    Thanks! Saved me an headache

  27. mac October 26th, 2009 6:34 pm

    Thankyou very much for the solution

  28. Gareth Arch November 6th, 2009 10:23 pm

    Fantastic! Thanks for posting this. I probably would've been playing around with this for hours otherwise.

  29. xleon December 19th, 2009 4:27 pm

    Thank you!!!!
    I had the same problem with embeded fonts. Now it´s fixed.

  30. Husnain Ashfaq January 14th, 2010 2:48 am

    i have replace the paths with /../
    but still its not working, when i change "../" to "/../" my flex builder shows errors and by command amxmlx is not working :(

  31. Jakeslc February 11th, 2010 10:15 am

    Simple fix saved me hours. Thanks for sharing.

  32. Dustin February 25th, 2010 6:11 pm

    mad props! this was a huge help!

  33. Andrew March 10th, 2010 4:38 am

    Thanks! It helped me!

  34. Marc March 13th, 2010 4:56 pm

    Thanks! Ant building happily again :)

  35. Anonymous March 21st, 2010 4:27 pm

    Thank you

Leave a reply

*
To prove you are human (not an imperial spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word