Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 基于字符串参数的Flash嵌入图像_Image_Flash_Transcode - Fatal编程技术网

Image 基于字符串参数的Flash嵌入图像

Image 基于字符串参数的Flash嵌入图像,image,flash,transcode,Image,Flash,Transcode,我试图在RangedItem类的构造函数中嵌入一个映像 public class RangedItem extends Item{ public var speed:Number; public function RangedItem(s:Number, n:String, d:Number, path:String):void{ super(n, d); speed = s; [Embed(source=path, mimeTy

我试图在RangedItem类的构造函数中嵌入一个映像

public class RangedItem extends Item{

    public var speed:Number;
    public function RangedItem(s:Number, n:String, d:Number, path:String):void{
        super(n, d);
        speed = s;
        [Embed(source=path, mimeType="image/png")] const IMAGE:Class;
    }
}
下面是我用来构造该项的代码

items.push(new RangedItem(item.speed, item.name, item.damage, '/img/gun.png'));
但我有这些错误

col: 4: Error: unable to resolve 'path' for transcoding
col: 4: Error: Unable to transcode path.
img/gun.png确实存在,因为如果我用“img/gun.png”替换路径,一切都正常

顺便说一句,我正在使用Flash朋克框架,如果这有什么变化的话。
我做错了什么?
提前谢谢

元数据在编译时使用,而不是在运行时使用。因此,您尝试在此处使用
path
执行的变量插值将不起作用:

[Embed(source=path, mimeType="image/png")] const IMAGE:Class;
编译器需要一个带有图像路径的文本字符串:

[Embed(source="path/to/my/image.png", mimeType="image/png")] const IMAGE:Class;

您可能会考虑创建一个包含您所有嵌入图像的单子(或您最喜欢的模式)类。然后,您的类可以引用singleton类中的资产,甚至可以在其他类的构造函数中传递对它们的引用