flex编译错误说明
来源:互联网 发布:宽带网络有哪些 编辑:程序博客网 时间:2024/06/05 19:50
rss
和 xml
命名空间。每个命名空间为 hello()
函数定义了不同的值。trace(hello())
语句返回此错误,因为它无法确定使用哪个命名空间。private namespace rss;private namespace xml; public function ErrorExamples() { use namespace rss; use namespace xml; trace(hello());} rss function hello():String { return "hola"; } xml function hello():String { return "foo"; }
通过使用具体的引用来纠正不明确的引用。下面的示例 使用 namespace::function形式指定所要使用的命名空间:
public function ErrorExamples() { trace(rss::hello()); trace(xml::hello());}
super
语句。只能在类实例的内部使用 super
语句。 override
关键字。 virtual
属性。 final
。 override
属性对其进行显式声明,如下面的示例所示:public override function foo():void{};
final
。 functionfoo(x,...(rest))
表达式中所示。 this
关键字,因为 this
可能没有上下文。 如果所要引用的类没有在使用的命名空间中定义或未定义为公共,也会出现该错误:
public class Foo{}
If you are using Flex™ Builder™ 2 and theclass is in a library, make sure to set the class path for theproject.
new
表达式中使用。class D { function xx() { return 22; } }var d:D = new D();var x = new d.xx(); // error, method cannot be used as constructorfunction yy() { this.a = 22; }var z = new yy(); // no error, global functions can be used as constructors.
void
返回类型的方法中使用 return
语句。 public function set gamma(g:Number):Number;
下面的语句是 有效的:
public function set gamma(g:Number):void;
在下面的示例中,第 3 行会生成错误,因为不存在为 xx
定义的 setter 函数:
class D { function get xx() { return 22; } }var d:D = new D();d.xx = 44; // error, property is read-only
public int z;// should be 'public var z:int;'
编译器遇到意外字符时,也会出现此错误。例如,由于缺少括号,下面使用的 trace()
函数无效(正确的语法是 trace("hello")
):trace "hello"
default xml namespace =
ns。或者缺少关键字xml
(注意小写),或者使用了错误的关键字。有关详细信息,请参阅默认的xml 命名空间指令。 case
语句。下面的 switch块错误地在第一个 case
语句之前包含对print
的调用:switch(x){trace(2);case 0: trace(0); break}
var sum:int = 1 + 2 + ;
如果错误是“_ 之前应有左括号”,则表示条件表达式中可能遗漏括号,如下面的示例(有意出错)所示:
var fact:int = 1 * 2 * 3;if fact > 2 { var bigger:Boolean = true;}
if
语句中缺少某项条件):var x = (5 > 2) ? trace(x)
include
语句。例如,下面的 a.as 和b.as 文件会生成此错误,因为每个文件都试图包含另外一个文件。文件 a.as 包含以下代码,它试图包含文件 b.as:
import foo.bar.baz;include "b.as"trace(2);
文件 b.as 包含以下代码,它试图包含文件 a.as:
include "a.as"
class a extends b { }class b extends a { }
可能使用的是超级类型,但需要的是子类型。例如:
class A {}var a:A = new A(); class B extends A { function f() }var b : B = a // error
最后一个语句会出错,因为该语句尝试将类型 A 的对象赋给类型 B 的变量。
同样,下面定义的 foo()
函数采用了类型B 的参数。语句 foo(a);
会出错,因为该语句尝试使用类型 A 的参数:
function foo(x:B) { }foo(a);
此外,下面的语句也会出错,因为 foo2()
的返回值必须为类型 B:
function foo2():B { return new A(); }
assortment
的属性:var i:int = 44;var str:String = i.assortment;
只有当编译器在严谨模式下运行时才会出现此错误。 huh
,调用该变量时会生成此错误:huh = 55;
只有编译器在严格模式下运行时,才会出现此错误。 public static public varx;
会生成此错误,因为该语句两次指定变量 x
是公共变量。请删除重复的声明。 goo
具有两个参数:class A { static function goo(x:int,y:int) { return(x+y); } }
下面的语句可能会出错,因为该语句提供了三个参数:
A.goo(1,2,3);
native
,因为它是一个保留关键字。 for
循环中使用的块) 视为属于同一个范围。下面的代码示例可以正确地将变量 x
转换为相同类型:
function test(){ var x:int = 3; for(var x:int = 33; x < 55; x++) trace(x); for(var x:int = 11; x < 33; x++) trace(x)}
下面的代码示例会生成错误,因为变量声明和 for
循环中的类型转换是不同的:
function test(){ var x:String = "The answer is"; for(var x:int = 33; x < 55; x++) // error trace(x); for(var x:unit = 11; x < 33; x++) // error trace(x)}
native
,因为它是一个保留关键字。 interface A { public function f(); };class C implements A,A {public function f() { trace("f"); }}
正确的实现语句应为 class C implements A{
。
topLevel()
要输出搕op斠淮省第二个语句会生成错误,因为该语句赋给该函数不同的返回值:function topLevel() { trace("top"); }topLevel = function() { trace("replacement works in ~");} // error
f(x)
不会生成错误,因为 if..else
语句总是返回值:function f(x):int{if (x) return 2;else return 3;} // no error
但是,下面的函数 g(x)
会生成该错误,因为switch
语句并非总是返回值。
function g(x:int):int{switch(x){ case 1: return 1; case 2: return 2:}// return 2;//uncomment to remove the error}
只有函数声明的返回类型不是 void 时,才启用此检查。