Embodding Asets with AS 3


http://www.bit-101.com/blog/?p=853
AS 3において、メタデータを使用してリソースを埋め込む例:

package
{
	import flash.display.Bitmap;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.media.Sound;
	import flash.text.Font;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFieldAutoSize;
 
	public class Main extends Sprite {
 
		[Embed(source = '../assets/fd-logo.jpg')]
		private var EmbeddedImage:Class;
		private var image:Bitmap;
 
		[Embed(source = '../assets/clip.swf', symbol = 'EmbeddedClipExample')]
		private var EmbeddedClip:Class;
		private var clip:MovieClip;
 
		[Embed(source = '../assets/bird-sound.mp3')]
		private var EmbeddedSound:Class;
		private var sound:Sound;
 
		[Embed(source='../assets/Arborcrest.ttf', fontName='Arborcrest')]
		public var EmbeddedFont:Class;
		private var field:TextField;
 
		public function Main():void {
			image = new EmbeddedImage();
			image.x = 50;
			image.y = 50;
			addChild(image);
 
			clip = new EmbeddedClip();
			clip.x = 200;
			clip.y = 50;
			addChild(clip);
 
			var s:Sound = new EmbeddedSound();
			s.play(0, 1000);
 
			Font.registerFont(EmbeddedFont);
			var style:TextFormat = new TextFormat();
			style.font = "Arborcrest";
			style.size = 45;
			field = new TextField();
			field.autoSize = TextFieldAutoSize.LEFT;
			field.embedFonts = true;
			field.defaultTextFormat = style;
			field.text = "Embedded Font Example";
			field.x = 50;
			field.y = 150;
			addChild(field);
		}
	}
}
Flexでコンパイルしなければならないので、Flashのコンパイラは自動的にメタデータを無視します。