是否可以创建动态嵌入功能?

发布于 2024-12-08 02:04:43 字数 362 浏览 0 评论 0原文

是否可以在 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

或以其他方式,或者即使它完全可能?

Is it possible to create dynamic embed function in 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

神魇的王 2024-12-15 02:04:43

您可以使用“动态”部分获得的最接近的是创建一个包装类,您可以在其中定义图像,并且稍后可以通过 id 将它们获取为位图。
不幸的是,这些属性是公共的,否则 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;
    }
}
}

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.
Unfortunately the properties are public, otherwise the hasOwnProperty function doesn't return 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;
    }
}
}
鹤仙姿 2024-12-15 02:04:43

嵌入元素在编译时嵌入。您无法在编译时动态嵌入某些内容...如果您想动态加载资源,请使用 加载器

Embedded elements are embedded at compile time. You can't dynamically embed something at compile time... If you want to load resources dynamically, use the Loader.

晒暮凉 2024-12-15 02:04:43

不,嵌入源是在编译时嵌入的。您不能在运行时嵌入任何内容。这就是嵌入的意思,在构建 swf 期间嵌入。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文