PDA

View Full Version : Exported Library Symbols refuse Constructor Parameters?



Ayman
July 31st, 2008, 09:37 AM
Regarding exporting a movieclip asset in the library, to be used as a class through actionscript, say you have this class (taken from the help example) for a Circle movieclip in the library:



package
{
import flash.display.MovieClip;

public class Circle extends MovieClip
{
public function Circle()
{
}

public function getArea():Number
{
return Math.PI * Math.pow((width / 2), 2);
}

}
}


Now I want the Circle() constructor to take a parameter (so replaced the function with another one which takes a parameter).



public function Circle(x:Number)
{
trace(x);
}


This has been causing me problems. In the linkage settings, when I chose the Class: DefaultCircle , and Base Class: Circle ,
and in the maintimeline I put something like var myCircle = new DefaultCircle(1) it gives this error:
1136: Incorrect number of arguments. Expected 0.

It basically does not want to take any other parameters for the constructor. It only works when I set the linkage settings to
Class: Circle , and Base Class: flash.display.MovieClip , and change the code in the maintimeline to var myCircle = new
Circle(1) . In this case it works. I want to know why the first scenario doesnt work!
Thanks!

senocular
July 31st, 2008, 09:56 AM
where is DefaultCircle coming from?

you can have parameters you just have to make sure they're used right and being passed (or made defaultable)

Ayman
July 31st, 2008, 01:38 PM
DefaultCircle is just the name of the Class I put in the Linkage settings. It gets auto-created.

senocular
July 31st, 2008, 01:46 PM
Being auto generated, it will be generated with no parameters. You'll have to use your own class as the movie clip Class.

Ayman
July 31st, 2008, 02:52 PM
ahh dammit. But it doesnt really make sense. At least since the base class has a constructor that takes parameters, the autogenerated class should inherit this constructor. Right?

senocular
July 31st, 2008, 03:23 PM
Flash can't guarantee that you'll always create instances via ActionScript. If that symbol is placed on the timeline, it would be instantiated without arguments meaning the parameters for the constructor needs to have no required arguments.

Ayman
August 1st, 2008, 03:09 AM
Flash can't guarantee that you'll always create instances via ActionScript. If that symbol is placed on the timeline, it would be instantiated without arguments meaning the parameters for the constructor needs to have no required arguments.

That's a good justification. Now I'm convinced :)

tkshredder
August 1st, 2008, 10:12 AM
Hi,

I'm having a similar problem involving constructors and packages.

Essentially, I am teaching myself AS3 right now through a game programming exercise and recently decided to reorganize all elements of my game into packages, following standard AS3 package designs. While everything seems to be structured correctly, I'm getting the 1136: Incorrect number of arguments. Expected 0. error.

Generally speaking, I have this structed as
app.enemies
app.attacks

for my packages.

It is likewise important to mention that I have this program working fine without packages. However, as this project is quickly becoming large, I would like to move it into packages.

If possible, please take a look at my source code. I would greatly appreciate any help you could offer!

Working (without packages)
www.panyamedia.com/flash/PackageTest.zip (http://www.panyamedia.com/flash/PackageTest.zip)

Not Working (with packages)
www.panyamedia.com/flash/PackageTest_v2.zip (http://www.panyamedia.com/flash/PackageTest_v2.zip)

tkshredder
August 4th, 2008, 05:32 PM
Got it fixed. I had incorrectly set the linkage on my MovieClips in the library.
Correct linkage is:

(Horsefly class)
Class: app.enemies.Horsefly
Base: flash.display.MovieClip

(Fireball class)
Class: app.attacks.Fireball
Base: flash.display.MovieClip

Yep, I'm still learning...