资产 class 调用不工作
Assets class calls not working
我正在制作一个 class,其中嵌入了我需要的所有资源,图标、字体、图像等;我从阿德里安的回答中得到它 here.
这几乎是它的结构:
public class Assets
{
[Embed(source = "../assets/images/imageBG.png")]
private static var imageBG:Class;
[Bindable]
private var imageName:Class;//There wasn't a ";" here, no error but I added it just in case
public static function setImage(newImageName:Class):void
{
imageName = newImageName:Class;
}
}
而且我应该在同一个包上使用来自不同 class 的类似内容来调用我需要的资产(尽管它应该在任何其他 class 中工作)
image = new Assets.setImage(imageBG) as Bitmap;
照原样推"Label must be a simple identifier."
如果我改变
imageName = newImageName:Class;
至
imageName = newImageName; //The "Class" part was pointed as the error
它推这个 "Access of undefined property imageName."
什么时候在函数上被调用,而 this 从哪里被调用
"Method cannot be used as a constructor."
指向 "Assets." 部分之后。
我显然做错了什么,但我不知道是什么,如果有人能帮忙的话。
此外,如果我问我如何更改内容以便调用资产并将其名称作为字符串传递,可以吗?还是我应该再问一个问题?
提前致谢。
imageName 不是静态的,因此不存在于静态范围内。
您提到的答案尽管有错误,但已被接受。它也仅适用于 Flex 项目。这是相同的但已更正:
public class Assets
{
static private var assetref:Object = {};
[Embed(source = "../assets/images/imageBG.png")]
private static var imageBG:Class;
assetref["imageBG"] = imageBG;
public static function getImage(newImageName:String):Bitmap
{
if(assetref[newImageName])
{
return new assetref[newImageName]();
}
return null;
}
}
只需将您需要的资产的名称作为字符串传递,如果它存在,您将返回一个准备显示的位图。
我正在制作一个 class,其中嵌入了我需要的所有资源,图标、字体、图像等;我从阿德里安的回答中得到它 here.
这几乎是它的结构:
public class Assets
{
[Embed(source = "../assets/images/imageBG.png")]
private static var imageBG:Class;
[Bindable]
private var imageName:Class;//There wasn't a ";" here, no error but I added it just in case
public static function setImage(newImageName:Class):void
{
imageName = newImageName:Class;
}
}
而且我应该在同一个包上使用来自不同 class 的类似内容来调用我需要的资产(尽管它应该在任何其他 class 中工作)
image = new Assets.setImage(imageBG) as Bitmap;
照原样推"Label must be a simple identifier."
如果我改变
imageName = newImageName:Class;
至
imageName = newImageName; //The "Class" part was pointed as the error
它推这个 "Access of undefined property imageName."
什么时候在函数上被调用,而 this 从哪里被调用
"Method cannot be used as a constructor."
指向 "Assets." 部分之后。
我显然做错了什么,但我不知道是什么,如果有人能帮忙的话。
此外,如果我问我如何更改内容以便调用资产并将其名称作为字符串传递,可以吗?还是我应该再问一个问题?
提前致谢。
imageName 不是静态的,因此不存在于静态范围内。
您提到的答案尽管有错误,但已被接受。它也仅适用于 Flex 项目。这是相同的但已更正:
public class Assets
{
static private var assetref:Object = {};
[Embed(source = "../assets/images/imageBG.png")]
private static var imageBG:Class;
assetref["imageBG"] = imageBG;
public static function getImage(newImageName:String):Bitmap
{
if(assetref[newImageName])
{
return new assetref[newImageName]();
}
return null;
}
}
只需将您需要的资产的名称作为字符串传递,如果它存在,您将返回一个准备显示的位图。