[英]An external swf in Flash builder
I embed an external swf in flash builder like so: 我将外部SWF嵌入到Flash Builder中,如下所示:
[Embed(source="assets/sounds/mytestswf.swf")]
private static var mySwf: Class;
How can I access it and add it to another sprite on stage? 如何在舞台上访问它并将其添加到另一个精灵?
i don't think you need a loader, that's for libraries that are added at runtime. 我认为您不需要装载程序,那是针对在运行时添加的库的。 Embed compiles the assets directly in the swf, so
addChild(new mySwf());
Embed直接在swf中编译资产,因此
addChild(new mySwf());
is enough to add it to the the display object list. 足以将其添加到显示对象列表中。
obviously, you'd like to assign it to a variable, so 显然,您希望将其分配给变量,因此
var $mySwf:mySwf = new mySwf();
addChild($mySwf);
On a side note, you should name your classes consistently. 附带说明一下,您应该为班级命名一致。 Class names start with the first letter capitalized, so you can tell it apart from variables
类名以首字母大写开头,因此您可以区分变量
[Embed(source="/assets/sounds/mytestswf.swf")]
private static var MySwf: Class;
...
var $mySwf:MySwf = new MySwf();
addChild($mySwf);
First, you need to specify mimeType="application/octet-stream"
on your Embed
. 首先,您需要在
Embed
上指定mimeType="application/octet-stream"
。 Then, you need to create a Loader
instance and use the Loader.loadBytes()
method to load the ByteArray
associated with the embedded class: 然后,您需要创建一个
Loader
实例,并使用Loader.loadBytes()
方法来加载与嵌入式类关联的ByteArray
:
var bytes:ByteArray = new mySwf();
var loader:Loader = new Loader();
loader.loadBytes(bytes);
addChild(loader);
Reference for learning: Loader.loadBytes() method 学习参考: Loader.loadBytes()方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.