Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Error 1136: expects 0 arguments but constructor needs 2

Participant ,
Feb 14, 2013 Feb 14, 2013

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.

TOPICS
ActionScript
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 14, 2013 Feb 14, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 14, 2013 Feb 14, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 14, 2013 Feb 14, 2013

Try using the actual code you posted (without the void). I suspect you won't see any errors. Work backward from there.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 14, 2013 Feb 14, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 14, 2013 Feb 14, 2013

Thank you both. My example code doens't show the error, so yeah, it must be something else. Onward to debugging...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 14, 2013 Feb 14, 2013
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 14, 2013 Feb 14, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines