In previous versions of Flash up to Flash CS3 , Flash did not support many of the Flex Metadata such as :
* Embed
* IconFile
* ResourceBundle
* Style
The most common metadata complained about is Embed metadata. Flash CS4 has added support to many of these metadata which will help developers to write code in Flex and testing it in Flash without worrying about incompatibilities at least in this area. In this post am going to talk about Embed metadata and show some examples.
Users can use embed metadata to embed the following type of assets :
* Image (GIF, JPEG, PNG).
* SVG.
* Sounds.
* SWFs (both AS2 and AS3).
* Symbols extracted from SWFs (not sure if AS2 or AS3 or both supported).
* Fonts from AS2 SWFs only (i think, maybe from AS3 SWFs as well).
Example : in the following example am going to embed GIF using Embed metadata.
1. Launch Flash CS4
2. File > New and select "Actionscript File".
3. Copy and paste the following code
package {
import flash.display.*;
public class GIFEmbed extends Sprite {
[Embed(source="../assets/tala.gif")]
private var theClass:Class;
public function GIFEmbed() {
var displayObj:DisplayObject = new theClass();
addChild(displayObj);
}
}
}
4. Save the AS file and give it a same name as the class name " GIFEmbed.as "
Note : [Embed(source="yourAssets.gif")] this is where you point to the actual assets.Please change the yourAssets.gif with the absolute path or relative path to your assets.
5. Create a Fla file and save it in the same place where the AS file is.
6. Add the GIFEmbed.as file as document class.
7. Test Movie.
8. You will get the following warning message as follow :
9. Click "Update Library path" button to add the path of the Flex.SWC to your library path.
10. Test Movie. Your image should be successfully embedded.