:: EDIT ::
This question is a little sprawling, so I’m trimming it down to make it more concise.
SUMMARY:
When I have a class linked to a MovieClip in my library and that class takes an argument in its constructor method. That class will compile properly ONLY when it’s located in my top-level directory (same dir as the .fla and Document.as files). If I move that class to a deeper directory, say com.place, and update the package statement and symbol link appropriately, the compiler will generate error “1136: Incorrect number of arguments. Expected 0.”
TO RECREATE:
-
Create flash project and put a rectangle on the stage. Covert it to symbol and assign it to class TestPanel – or whatever you choose. Also configure the fla so that is uses a Document (Main) class.
-
Create Main.as and TestPanel.as in the same folder. In the Main class, instantiate a instance of TestPanel and add it to the stage. Flash will, predictably, add the rectangle symbol and everything is fine.
-
Now modify TestPanel so that its constructor method takes a Number and have Main.as pass some number to TestPanel.
public function TestPanel( num:Number )
{
trace( ‘TestPanel is created: num = ‘ + num );
}public function Main()
{
trace( ‘Main is initialized’ );
var myTestPanel:TestPanel = new TestPanel( 5 );
addChild( myTestPanel );
} -
Now move TestPanel to com/place/TestPanel and update the package statement to reflect its new location. Also update the rectangle symbol in the library so that it links to com.place.TestPanel.
You now get the error: 1136: Incorrect number of arguments. Expected 0.
When I move the TestPanel.as into a deeper directory, Flash somehow is looking elsewhere for the base class for Symbol, even though I’m mapping that Symbol to com.place.TestPanel.
Can anybody recreate this and tell me where I’m tripping up?
( sorry for not highlighting the code in this post. I can’t seem to get this editor to work properly )
I realized where I’m getting my error.
First, thanks for everybody’s input.
What happened was that my Symbol was linking to my class in the ‘Base class’ field as opposed to the ‘Class’ field. I don’t know exactly when I started this habit but I’ve been doing it forever and apparently it didn’t matter because none of my classes used arguments in their constructor- until now. This also explains why it works in the top-level directory and not when nested in com/place/whatever.
For anybody who stumbles upon this same/similar problem, remember to check to see that you symbol links to your class in the ‘Class’ field, not the ‘Base Class’ field.
Here’s a link a Adobe’s documentation on the subject.