简体   繁体   English

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

[英]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;
    }
}
}

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 . 您不能在编译时动态地嵌入某些内容...如果您想动态地加载资源,请使用Loader

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.

相关问题 是否可以在运行时嵌入 fonts 以用于 SWF 中现有的动态文本字段实例? - Is it possible to embed fonts at runtime to use for existing dynamic textfield instances in SWFs? 如何在动态文本上嵌入字体 - How to embed font on dynamic text 是否可以将flv文件嵌入到闪存中? - Is it possible to embed flv file in to flash? 是否可以在Flash CS3中使用`[Embed source =`...“? - Is it possible to use `[Embed source=`… with Flash CS3? 是否可以将现有SWF嵌入到Air for iOS应用程序中? - Is it possible to embed an existing SWF into an Air for iOS app? 是否可以嵌入文件夹中的所有文件? - Is it possible to embed all files from a folder? 当动态滚动文本到达底部时,可以调用Flash(AS3)函数吗? - Possible to call a Flash (AS3) function when dynamic scrolling text has reached the bottom? 有没有办法在Flash AS3电影中嵌入编译时动态时间戳? - Is there a way to embed a compile-time dynamic timestamp in a Flash AS3 movie? 是否可以在AS3项目中嵌入mp4电影? (无netstream) - Is it possible to embed an mp4 movie in an AS3 project? (no netstream) 在制作iPhone应用程序时是否可以嵌入或加载SWF(Apple是否允许) - Is it possible to embed or load SWFs when making iphone apps (Is it allowed by Apple)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM