Flash Builder无法识别某些关键字

时间:2013-03-18 02:56:27

标签: actionscript-3 flex flash-builder undefined starling-framework

我正在尝试按照本教程

http://tv.adobe.com/watch/starting-with-starling/starting-with-starling-welcome-screen/

当我尝试创建Assets.as类(从大约7分钟开始)时,FB无法识别某些关键字。特别是字典,纹理和位图。听到代码......

   private static var gameTextures:Dictionary = new Dictionary();   
   public static function getTexture(name:String):Texture
   {
   if (gameTextures[name] == undefined)
   {
   var bitmap:Bitmap = new Assets[name]();
   gameTextures[name] = Texture.fromBitmap(bitmap);
   }
   return gameTextures[name];

我一直密切关注教程系列,直到这一点,但我仍然遇到这些错误。

调用可能未定义的Dictionary方法 未找到类型或不是编译时常量:纹理,字典和位图 访问可能未定义的属性:纹理

我很感激我能解决这个问题的任何帮助,谢谢。

1 个答案:

答案 0 :(得分:1)

我想您忘记导入已命名的类。在使用框架中的类之前,必须将其导入到类中:

package 
{
    import flash.display.Bitmap;
    import flash.display3D.textures.Texture;
    import flash.utils.Dictionary;

    public class Assets
    {
        private static var gameTextures:Dictionary = new Dictionary();   

        public static function getTexture(name:String):Texture
        {
            if (gameTextures[name] == undefined)
            {
                var bitmap:Bitmap = new Assets[name]();
                gameTextures[name] = Texture.fromBitMap(bitmap);
            }
            return gameTextures[name];
        }
    }
}

此外,在Flash Builder中,您可以在Mac OS上键入CTRL + SHIFT + OCMD + SHIFT + O)来清除导入。这将添加任何所需的import语句,并在出现冲突时询问您(例如使用Texture)。它也将删除任何不必要的导入。

在代码中键入类的名称时,可以按CTRL + SPACE进行自动完成。然后,也会自动导入所选类。