There are some interesting tips I found during the time I work on Flex Programming. I will cover Embedding, Binding, Event Handling, Function Pointer, Mixin and more. I hope these tips will make your life easier when you work on Flex.
Tip 1: Embedding
Many Adobe Flex applications use external assets like images, sounds, and fonts. Although you can reference and load assets at run time, you often compile these assets into your applications. The process of compiling an asset into your application is called embedding the asset. Flex lets you embed image files, movie files, MP3 files, and TrueType fonts into your applications… When you embed an asset, you compile it into your application’s SWF file. The advantage of embedding an asset is that it is included in the SWF file, and can be accessed faster than when the application has to load it from a remote location at run time. The disadvantage of embedding an asset is that your SWF file is larger than if you load the asset at run time – Adobe
There are 3 ways to embed asset to Flex. In Flex code, you can use directive @Embed for direct use or you can associate the embedded asset with a variable by using the [Embed] metadata tag. In Style, you can use Embed to associate asset as well. Go check the syntax in detailed here.
Flex also have an option to embed any kind of file at compile time. The trick is with the ‘mimeType‘ option of the [Embedd] tag. while embedding other kind of files like text (or any) we need to specify ‘application/octet-stream‘ for mimeType option. Here is the sample:
[Bindable] [Embed(source="MyFile.txt", mimeType="application/octet-stream")] private var myFileClass:Class; ... var MyFileByteArray:ByteArrayAsset = ByteArrayAsset(new myFileClass()); var story:String = MyFileByteArray.readUTFBytes(MyFileByteArray.length);
You must specify that the MIME type for the embedding is application/octet-stream, which causes the byte data to be embedded “as is”, with no interpretation. It also causes the autogenerated class to extend ByteArrayAsset rather than another asset class. For example, if you embed a PNG file without specifying this MIME type, the PNG data will be automatically transcoded into the bitmap format used by the player, and a subclass of BitmapAsset will be autogenerated to represent it. But if you specify the MIME type as application/octet-stream, then no transcoding will occur, the PNG data will be embedded as is, and the autogenerated class will extend ByteArrayAsset.
Tip 2: Binding







No comments yet.