【问题标题】:Is "World" reserved Class name in AS3?“世界”是 AS3 中的保留类名称吗?
【发布时间】:2011-05-11 08:49:43
【问题描述】:

有没有人知道“世界”被保留或以该名称内置在类中? 当我尝试构建我创建的 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..

【问题讨论】:

  • 尝试将类名更改为其他名称,看看同样的问题是否仍然存在。
  • 试过了,它可以使用不同的名称。 :] 但我想要那个“世界”的名字。 :D
  • 这当然是个谜,这会更好理解。但如果它有帮助,我可信赖的词库已经返回了这些潜在的替代品:地球、地球、行星、球体、月亮、星星、天体、球体、社会、圈子、竞技场、环境、省、域、轨道、保存、领域、领域、学科、地区、部门、每个人、每个人、人、人类、公众、人口。
  • 不!哈哈。我真的想提供帮助。我经常回去重命名我的类和变量,因为我想到或使用同义词库来研究更合适的标题。
  • 这来晚了,因为我今天早些时候第一次遇到这个问题。我分解了默认 as3 CS5 包含路径中的库,结果发现 World 是与 fl.ik 包关联的顶级类;用于管理骨架动画的逆运动学库。希望这可以帮助。 World 类位于 ik.swc。

标签: actionscript-3 flash reserved-words class-names


【解决方案1】:

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

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

丑陋,但它有效!

【讨论】:

  • +1 是的,我也遇到过这个问题。我的游戏在 CS4 上为 Flash Player 10 编译得很好,但后来在用 CS5 编译时我收到了编译错误。我认为那一定是 10.1 的问题?
【解决方案2】:

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

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

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

【讨论】:

  • 不,没有其他世界级。一切 - 进口,包装......一切都是正确的。
  • 好吧,在新文档中创建一个新的世界对象 (new World();) 会引发错误,指出它找不到类,所以它一定是您正在导入的东西。跨度>
【解决方案3】:

其他几种可能性:

您是否在使用 Flex/FlashBuilder 并导入 SWC?那些可以在不泄露源代码的情况下公开类。

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

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

【讨论】:

  • 嗯,没有。使用 flash cs5 进行编码。没有图书馆项目有这个类名。
【解决方案4】:

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

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

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

        }
    }
}

【讨论】:

    【解决方案5】:

    这有点牵强,但请尝试删除您的 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");
            }
        }
    }
    

    【讨论】:

      【解决方案6】:

      我只是自己检查它,即使它是一个已经回答的旧帖子。 原因是我通过搜索AS3中的保留关键字列表找到了这篇文章。

      “世界”关键字未保留 :) 哎呀...

      这是我目前在 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"
                              ]
      

      【讨论】:

        猜你喜欢
        • 2011-07-16
        • 1970-01-01
        • 1970-01-01
        • 2011-07-24
        • 1970-01-01
        • 1970-01-01
        • 2016-08-19
        • 2019-10-21
        • 2022-08-26
        相关资源
        最近更新 更多