[英]Is it possible to create dynamic embed function?
Is it possible to create dynamic embed function in ActionScript3 是否可以在ActionScript3中创建动态嵌入功能
for example like this 例如这样
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
or maybe in some other way, or even if it is at all possible? 或也许以其他方式,甚至完全有可能?
The closest you can get with the "dynamic" part, is to create a wrapper class, where you define your images, and you can get them as Bitmap later on by an id. 使用“动态”部分可以获得的最接近的结果是创建一个包装类,在其中定义图像,然后可以通过id将它们作为Bitmap获取。 Unfortunately the properties are public, otherwise the hasOwnProperty function doesn't return true.
不幸的是,这些属性是公共的,否则hasOwnProperty函数不会返回true。 (If someone finds a better way, please let me know)
(如果有人找到更好的方法,请告诉我)
See below: 见下文:
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;
}
}
}
No, embed source is embedded at compile time. 不,嵌入源在编译时嵌入。 You can not embed anything at run time.
您无法在运行时嵌入任何内容。 That's what embed means, embedding during building the swf.
这就是embed的意思,即在构建swf时嵌入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.