Embedding Assets with AS3
在AS3中使用元数据嵌入资源的例子:
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的编译器自动忽略元数据。
其他参考:
Bit-101 Embedding Resources with AS3
Tags: actionscript, embed


