是“世界”吗? AS3 中保留的类名?

发布于 2024-10-02 12:45:13 字数 408 浏览 5 评论 0原文

有谁知道有关“世界”以该名称在类中保留或构建的信息吗? 当我尝试构造我创建的 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.

Grr..

Does anyone knows something about "World" being reserved or built in class with that name?
when I try to construct the World class I've created it throws compile error:

1136: Incorrect number of arguments.  Expected 2.

But I've million times checked, there are no arguments expected at all, all package naming, variable types.. everything is correct, but it throws that stupid error. :/
Try it on your own and you will see that it does.. or I'm stupid?

When I try to call init function in the World class it throws this one:

1061: Call to a possibly undefined method init through a reference with static type World.

Grr..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

自由范儿 2024-10-09 12:45:13

我也遇到过同样的问题。我认为它是从 FlashPlayer 10(可能是 10.1,但不能确定)开始保留的。在引用我的世界类时,我必须使用完整的包名称来解决这个问题。

var myWorld:com.foo.World = new com.foo.World();

丑陋,但有效!

I have had this same problem. I think it is reserved as of FlashPlayer 10 (possibly 10.1, but can't be sure). I had to work around it by using my full package name when referencing my World class.

var myWorld:com.foo.World = new com.foo.World();

Ugly, but it works!

岁月苍老的讽刺 2024-10-09 12:45:13

您的源路径中的某个位置必须有另一个名为 World 的类。看看你的进口。

如果需要,请输入完整的包路径,以避免与其他地方的另一个 World 类混淆:

var w:my.package.World = new my.package.World();

You must have another class called World somewhere in your source path. Look at your imports.

Type the full package path if neccessary to avoid confusion with another World class somewhere else:

var w:my.package.World = new my.package.World();
断念 2024-10-09 12:45:13

其他几种可能性:

您是否使用 Flex/FlashBuilder 并导入 SWC?这些可以公开类而不泄露源代码。

或者您是从 FLA 进行编译的吗?在这种情况下,可能存在导出到名称与您的名称冲突的 ActionScript 类的库符号。

另一种可能性是您正在使用的 Flash 编译器(无论是 FlashPro 还是 FlashBuilder)未正确缓存您之前创建的类定义。我之前已经经历过几次这个错误。尝试执行项目/清理(在 FlashBuilder 中),或者,如果您绝望的话,创建一个新项目。

A couple of other possibilities:

Are you using Flex/FlashBuilder, and importing a SWC? Those can expose classes without revealing the source code.

Or are you compiling from a FLA? In that case, there may be a library symbol exporting to an ActionScript class whose name conflicts with yours.

Another possibility is that the Flash compiler you are using (whether FlashPro or FlashBuilder) has improperly cached a class definition you created earlier. I have experienced this bug a few times before. Try doing a Project/Clean (in FlashBuilder) or, if you're desperate, creating a new project.

月光色 2024-10-09 12:45:13

我认为您应该检查构造函数中所需的参数,并通过将 = null 或其他内容传递给构造函数来使它们成为可选参数。

当您从库中放置一个在构造函数中具有所需参数的符号时,可能会发生此“错误”。

package com.myworld
{
    public class World
    {
        public function World(parameter1:int = null, parameter2:String = null ) 
        {

        }
    }
}

I think you should check the parameters which are required in the constructor and make them optional by passing = null or something to the constructor-function.

This 'error' can occur when you place a symbol from your library which has required parameters in the constructor.

package com.myworld
{
    public class World
    {
        public function World(parameter1:int = null, parameter2:String = null ) 
        {

        }
    }
}
风为裳 2024-10-09 12:45:13

这是一个延伸,但请尝试删除您的 ASO 文件(控制 > 删除 ASO 文件)并重新编译。

如果这不起作用,我建议的唯一另一件事是重建您的项目,每次导入一个或一组类时测试这个问题。这种方法应该保证您至少找到问题的根源。

以下文档类在针对 Flash Player 10.1.53.64 (10.1) 的 Adob​​e Flash CS5 中编译和执行完全正常:

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");
        }
    }
}

this is a stretch, but try deleting your ASO files (Control > Delete ASO Files) and recompile.

if that doesn't work the only other thing i would suggest is to rebuild your project, testing this problem each time you import one or a group of classes. this approach should guarantee you to at least find the where the problem is originating.

the following document class compiles and executes completely fine for me in Adobe Flash CS5 targeting 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");
        }
    }
}
苦行僧 2024-10-09 12:45:13

我只是自己检查一下,即使这是一个已经回答的旧帖子。
原因是我在搜索 AS3 中的保留关键字列表时发现了这篇文章。

“World”关键字不是保留的:)哎呀...

这是我迄今为止在 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"
                        ]

I just check it myself even it was an old post that has been answered yet.
The reason is that I found this post due to a search about a list of reserved keywords in AS3.

The "World" Keyword is not reserved :) Oooops...

This is the list I found so far with reserved words / keywords in AS3:
If, you edit this list, please leave a comment / with sources... THX
Sometimes the same keyword may appear twice in the list under different categories...

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)

Here are the 3 Arrays of keywords :

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"
                        ]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文