AS3 Starling框架纹理Atlas TypeError#1007

时间:2012-07-24 00:07:24

标签: actionscript-3 error-handling sprite-sheet starling-framework

我是starling框架的新手,目前正在学习如何使用它。

我已经从嵌入式PNG文件中创建了纹理,其中starling框架完美地工作并显示在屏幕上,但我正在尝试使用spritesheet(Texture Atlas)工作,它正在给我这个:

“错误#1007:尝试对非构造函数进行实例化。”

从我所做的所有研究中,我所做的代码都应该有效。

以下是我的Assets类中适用的代码。

public class Assets
{
    [Embed(source="assets/sky.png")]
    private static var SKY_CLASS:Class;
    public static var SKY:Texture;

    [embed(source="assets/generalsheet.png")]
    private static var GENERAL_SHEET_CLASS:Class;       
    [embed(source="assets/generalsheet.xml", mimeType="application/octet-stream")]
    private static var GENERAL_ATLAS_CLASS:Class;
    public static var GENERAL_SHEET:TextureAtlas;

    public static function init():void
    {
        SKY = Texture.fromBitmap(new SKY_CLASS());
        GENERAL_SHEET = new TextureAtlas(Texture.fromBitmap(new GENERAL_SHEET_CLASS()), XML(new GENERAL_ATLAS_CLASS())); // this is where Flash Builder tells me there is an error
    }

1 个答案:

答案 0 :(得分:1)

您只需要在大写中编写Embed标记,只需更改:

[embed(source="assets/generalsheet.png")]
private static var GENERAL_SHEET_CLASS:Class;       
[embed(source="assets/generalsheet.xml", mimeType="application/octet-stream")]
private static var GENERAL_ATLAS_CLASS:Class;

为:

[Embed(source="assets/generalsheet.png")]
private static var GENERAL_SHEET_CLASS:Class;       
[Embed(source="assets/generalsheet.xml", mimeType="application/octet-stream")]
private static var GENERAL_ATLAS_CLASS:Class;

另外,类名通常用 UpperCamelCase 编写, ALL_CAPITALIZED 是为常量保留的。变量名通常用 lowerCamelCase lowercase_separated_by_underscore 编写。这是大多数ActionScript3(和Java)程序员遵循的惯例,如果您坚持使用它,您的代码将更易读,因此下次应该更容易帮助您;)

所以我建议:

[Embed(source="assets/sky.png")]
private static var SkyClass:Class;

public static var sky:Texture;

[Embed(source="assets/generalsheet.png")]
private static var GeneralSheetClass:Class;

[Embed(source="assets/generalsheet.xml", mimeType="application/octet-stream")]
private static var GeneralAtlasClass:Class;

public static var general_sheet;

public static function init():void
{
    sky = Texture.fromBitmap(new SkyClass());

    general_sheet = new TextureAtlas(Texture.fromBitmap(new GeneralSheetClass()), XML(new GeneralAtlasClass()));
}