Copy link to clipboard
Copied
Hi. In my project I have a Box class that extends MovieClip, and Box has instances of the Egg class. The Egg class receives two arguments on instantiation, month (a string) and size (an int).
Here's my code:
package com.stuff {
import flash.display.MovieClip;
import com.stuff.Egg;
public class Box extends MovieClip {
private var Egg1:Egg = new Egg("jan", 2);
private var Egg2:Egg = new Egg("feb", 5);
public function Box():void {
}
}
}
package com.stuff {
public class Egg {
public function Egg(m:String, s:int):void {
}
}
}
When I test the movie I get the following error: 1136: Incorrect number of arguments. Expected 0.
What am I doing wrong? Thank you.
Copy link to clipboard
Copied
The arguments look fine, but a constructor should not have any return value, even void. It's possible the compiler is giving you the wrong error with this situation. Note that if you use Flash Builder to create your Classes, you can create the constructor by checking a box. And you can add a constructor later (in FB) by typing constr Ctrl-Space-Enter.
Copy link to clipboard
Copied
Thank you so much, Amy. I tried removing the :void in both constructors, but the error remains. I'm using Flash CS6 on Mac OSX, by the way, in case this changes anything.
The code I'm using is a simplified example of my project, I didn't post the actual code because both classes are a bit big to post here and my code is in portuguese...
Copy link to clipboard
Copied
Try using the actual code you posted (without the void). I suspect you won't see any errors. Work backward from there.
Copy link to clipboard
Copied
I would still remove the :void on the constructors - it's not really a standard and makes the constructor stand out.
That said, maybe the error isn't with your constructor? Are you calling any functions inside of the Egg constructor in your actual code? I would watch for that. Try commenting lines out and adding them back 1 by 1 until you get the error.
Copy link to clipboard
Copied
Thank you both. My example code doens't show the error, so yeah, it must be something else. Onward to debugging...
Copy link to clipboard
Copied
Okay... Found it and now I'm a bit embarrased. This has been a long project and some time ago I created a MovieClip on the library and linked it to a class named Egg. That's why it expected 0 arguments, it was instancing that MovieClip. *facepalm*
Again, thank you for your help.
Copy link to clipboard
Copied
I doubt this is your issue but I never have return types on the constructor - depending on the version of the Flex SDK that you are using and program version maybe it does matter though? Maybe by adding the return type it is hiding that as the constructor.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now