![](/img/trans.png)
[英]Is it possible to embed fonts at runtime to use for existing dynamic textfield instances in SWFs?
[英]Is it possible to create dynamic embed function?
是否可以在ActionScript3中创建动态嵌入功能
例如这样
public function embedImage(path:String):Bitmap{
[Embed(source = path, mimeType = "image/png")]
var NewBitmapClass:Class;
var image:Bitmap=new NewBitmapClass();
return image;
}// tried it, it doesnt work
或也许以其他方式,甚至完全有可能?
使用“动态”部分可以获得的最接近的结果是创建一个包装类,在其中定义图像,然后可以通过id将它们作为Bitmap获取。 不幸的是,这些属性是公共的,否则hasOwnProperty函数不会返回true。 (如果有人找到更好的方法,请告诉我)
见下文:
package {
import flash.display.Bitmap;
public class DynamicEmbed {
[Embed(source = "../images/cat.jpg")]
public var cat : Class;
[Embed(source = "../images/parrot.jpg")]
public var parrot : Class;
[Embed(source = "../images/pig.jpg")]
public var pig : Class;
[Embed(source = "../images/quail.jpg")]
public var quail : Class;
public function DynamicEmbed() {
}
public function getBitmap(id : String) : Bitmap {
if(hasOwnProperty(id)) {
var bitmap : Bitmap = new this[id]();
return bitmap;
}
return null;
}
}
}
嵌入式元素是在编译时嵌入的。 您不能在编译时动态地嵌入某些内容...如果您想动态地加载资源,请使用Loader
。
不,嵌入源在编译时嵌入。 您无法在运行时嵌入任何内容。 这就是embed的意思,即在构建swf时嵌入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.