有没有人知道“世界”在课堂上保留或建造的名称? 当我尝试构建我创建的World类时,它会抛出编译错误:
1136: Incorrect number of arguments. Expected 2.
但我已经百万次检查,根本没有预期的参数,所有包命名,变量类型......一切都是正确的,但它会抛出那个愚蠢的错误。 :/ 自己尝试一下,你会发现它确实......或者我是愚蠢的?
当我尝试在World类中调用init函数时,它抛出了这个:
1061: Call to a possibly undefined method init through a reference with static type World.
格儿..
答案 0 :(得分:4)
我遇到过同样的问题。我认为它保留了FlashPlayer 10(可能是10.1,但不能确定)。我必须在引用我的World类时使用我的完整包名来解决它。
var myWorld:com.foo.World = new com.foo.World();
丑陋,但它确实有效!
答案 1 :(得分:1)
您的源路径中必须有另一个名为World的类。看看你的进口。
如果需要,请键入完整的包路径,以避免与其他地方的其他World类混淆:
var w:my.package.World = new my.package.World();
答案 2 :(得分:1)
其他几种可能性:
您使用的是Flex / FlashBuilder,还是导入了SWC?这些可以在不泄露源代码的情况下公开类。
或者您是从FLA编译的?在这种情况下,可能会有一个库符号导出到一个名称与您的名称冲突的ActionScript类。
另一种可能性是您正在使用的Flash编译器(无论是FlashPro还是FlashBuilder)未正确缓存您之前创建的类定义。我以前经历过几次这个bug。尝试做一个Project / Clean(在FlashBuilder中),或者,如果你很绝望,可以创建一个新项目。
答案 3 :(得分:0)
我认为您应该检查构造函数中所需的参数,并通过将= null或其他内容传递给构造函数来使它们成为可选参数。
当您从库中放置一个在构造函数中具有必需参数的符号时,可能会发生此“错误”。
package com.myworld
{
public class World
{
public function World(parameter1:int = null, parameter2:String = null )
{
}
}
}
答案 4 :(得分:0)
这是一个延伸,但尝试删除您的ASO文件(控制>删除ASO文件)并重新编译。
如果这不起作用,我建议的另一件事就是重建你的项目,每次导入一个或一组类时测试这个问题。这种方法应该保证你至少找到问题所在的位置。
以下文档类在Adobe Flash CS5中针对Flash Player 10.1.53.64(10.1)编译并执行完全正常:
package
{
import flash.display.Sprite;
import flash.events.Event;
public class World extends Sprite
{
public function World()
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(evt:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
trace("World Document Added To Stage");
}
}
}
答案 5 :(得分:0)
我自己检查一下,即使这是一个已经回答的旧帖子。 原因是我发现这篇文章是因为搜索了AS3中的保留关键字列表。
“World”关键字未保留:) Oooops ...
这是我到目前为止在AS3中找到保留字/关键字的列表: 如果您编辑此列表,请发表评论/来源...... THX 有时,相同的关键字可能会在不同类别的列表中出现两次...
0 : abstract (future keyword)
1 : as (reserved keyword)
2 : boolean (future keyword)
3 : break (reserved keyword)
4 : byte (future keyword)
5 : case (reserved keyword)
6 : cast (future keyword)
7 : catch (reserved keyword)
8 : char (future keyword)
9 : class (reserved keyword)
10 : const (reserved keyword)
11 : continue (reserved keyword)
12 : debugger (future keyword)
13 : default (reserved keyword)
14 : delete (reserved keyword)
15 : do (reserved keyword)
16 : double (future keyword)
17 : dynamic (syntactic keyword)
18 : each (syntactic keyword)
19 : else (reserved keyword)
20 : enum (future keyword)
21 : export (future keyword)
22 : extends (reserved keyword)
23 : false (reserved keyword)
24 : final (syntactic keyword)
25 : finally (reserved keyword)
26 : float (future keyword)
27 : for (reserved keyword)
28 : function (reserved keyword)
29 : get (syntactic keyword)
30 : goto (future keyword)
31 : if (reserved keyword)
32 : implements (reserved keyword)
33 : import (reserved keyword)
34 : in (reserved keyword)
35 : include (syntactic keyword)
36 : instanceof (reserved keyword)
37 : interface (reserved keyword)
38 : internal (reserved keyword)
39 : intrinsic (future keyword)
40 : is (reserved keyword)
41 : long (future keyword)
42 : namespace (syntactic keyword)
43 : native (reserved keyword)
44 : native (syntactic keyword)
45 : new (reserved keyword)
46 : null (reserved keyword)
47 : override (syntactic keyword)
48 : package (reserved keyword)
49 : private (reserved keyword)
50 : protected (reserved keyword)
51 : prototype (future keyword)
52 : public (reserved keyword)
53 : return (reserved keyword)
54 : set (syntactic keyword)
55 : short (future keyword)
56 : static (syntactic keyword)
57 : super (reserved keyword)
58 : switch (reserved keyword)
59 : synchronized (future keyword)
60 : this (reserved keyword)
61 : throw (reserved keyword)
62 : throws (future keyword)
63 : to (future keyword)
64 : to (reserved keyword)
65 : transient (future keyword)
66 : true (reserved keyword)
67 : try (reserved keyword)
68 : type (future keyword)
69 : typeof (reserved keyword)
70 : use (reserved keyword)
71 : var (reserved keyword)
72 : virtual (future keyword)
73 : void (reserved keyword)
74 : volatile (future keyword)
75 : while (reserved keyword)
76 : with (reserved keyword)
以下是3个关键字数组:
private static var reserved:Array = [
"as","break","case","catch","class","const","continue","default","delete",
"do","else","extends","false","finally","for","function","if","implements",
"import","in","instanceof","interface","internal","is","native","new","null",
"package","private","protected","public","return","super","switch","this",
"throw","to","true","try","typeof","use","var","void","while","with"
];
private static var syntactic:Array = [
"each","get","set","namespace","include","dynamic","final","native","override","static"
];
private static var future:Array = [
"abstract","boolean","byte","cast","char","debugger","double","enum","export","float",
"goto","intrinsic","long","prototype","short","synchronized","throws","to","transient",
"type","virtual","volatile"
]