开发者

Is "World" reserved Class name in AS3?

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..


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!


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();


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.


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 ) 
        {

        }
    }
}


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


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"
                        ]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜