As a matter of fact, I don’t like the Flex framework very much. To be honest, I don’t like it at all. IMO it’s totally overloaded, slow and grows your SWF’s filesize a lot.
Why I’m writing this post, is because I spend approximately 3-4 hours on searching for a solution and now that I’ve got this solution, I want to share this with you.
At the moment I build an application that loads our noob3D-Library dynamically. While developing I need syntax completion, to do fast coding without having to read the docs again and again ;)
For a normal project it would just be fine to include the lib into your SWF, but I want to load it seperately. To get mxmlc to “exclude” the noob3D-Library from my SWF, I can use the “external-library-path” compiler argument (in my case it’s a custom-flex-config.xml).
This works just fine and the noob3D-Library isn’t linked to my SWF. But this is where my journey begun on yesterday evening: If I use the “external-library-path” argument with mxmlc, also the Flex framework isn’t linked to the SWF anymore. I don’t know if this is a bug or if someone at Adobe smoked too much of whatever kind of plants grow in California ;-)
You might probably also got the nice Error message “VerifyError: Error #1014: Class IFlexAsset could not be found” or something similar in your language. This is what I got. I tried lots of things to “re-include” these Flex files, but nothing worked for me.
Somewhere during my research, I found out that you can also use the Embed tag on classes, rather than variables or consts. I read this concerning Font embedding, but it was mentioned that you can only embed one Font in one class with this. Since this was not what I wanted, I closed the page and continued searching.
However, I finally tried the solution to use Embed in another way ;)
You may know how to use the Embed tag with consts and vars, like this
public final class GeneralCursor { [Embed(source=''D:/Morpheus/src/assets/AwesayCursorArrow.png')] private static const AWESAY_CURSOR_ARROW_DATA:Class; [...] |
This includes the specified file as a Symbol into the SWF and works just fine for most of us. But this way uses the Flex framework. If you explore your SWF with your favorite tool of choice, you might see that classes like IFlexAsset, BitmapAsset, ByteArrayAsset, NameUtil, etc. are included in your SWF. But this is not the case if you use “external-library-path”, as I already mentioned above. So, now you may know why I was talking about smoking ;)
OK, what we can do instead is embedding our Symbols, Fonts, Bitmaps, XMLs, or any other data without using the Flex framework at all. It’s pretty simple!
For every file you want to include, you’ll have to create an own class. This class must inherit from the type of file you want to embed. For embedding Pictures, the class should inherit from Bitmap, if you want to include binary data, it should inherit from ByteArray.
Please NOTE: You can’t include XMLs as a subclass of XML, because the compiler isn’t able to transcode this. See the example code below.
Embedding XML files:
package com.badnoob.awesay.morpheus.embeds { import flash.utils.ByteArray; [Embed(source='D:/Morpheus/src/assets/xml/i18n/de-DE.xml', mimeType='application/octet-stream')] public final class FailSafeLanguageData extends ByteArray { public function FailSafeLanguageData():void {} } } |
Embedding Pictures:
package com.badnoob.awesay.morpheus.embeds { import flash.display.Bitmap; [Embed(source='D:/Morpheus/src/assets/AwesayCursorArrow.png')] public final class AwesayGeneralCursorData extends Bitmap { public function AwesayGeneralCursorData():void {} } } |
Using XML data:
package foo { import com.badnoob.awesay.morpheus.embeds.FailSafeLanguageData; import flash.utils.ByteArray public class EmdeddedXMLLoader { public static function loadEmbeddedXMLData():XML { var baFileData :ByteArray = new FailSafeLanguageData, strFileData :String = objFileData.readUTFBytes(objFileData.length); return XML(strFileData); } } } |
Using Pictures:
package foo { import com.badnoob.awesay.morpheus.embeds.AwesayGeneralCursorData; public class EmbeddedPictureLoader { public static function loadEmbeddedPicture():Bitmap { return new AwesayGeneralCursorData; } } } |
I hope this helps!



21:05, 26. July 2011Ray /
Great, I’ve tried and it works.
Since I can embed resources, now I don’t need to go to Windows to compile using Flash. I can continue work in Ubuntu using vim.
Thanks for your great work.