Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionScript-3 cannot have multiple constructors?

I have

    public function Shard() {     }      public function Shard(x:Number, y:Number, vx:Number, vy:Number, rotation:Number, spin:Number)     {       ...     } 

And I got on the second constructor:

Multiple constructor definitions found. Constructor may not be defined in code.

So, ActionScript-3 cannot have multiple constructors?

like image 765
The Student Avatar asked Aug 24 '10 18:08

The Student


1 Answers

No you can't have multiple contructor neither the same function with different signature, but you can use default arguments :

public function Shard(x:Number=NaN, y:Number=NaN) {   //... } 

then you can call new Shard() or new Shard(100) or new Shard(100, 200)

or you can also use variable arguments:

public function Shard(...args){  if (args.length==0) {    //...  } else {   //...   var firstArg:Object=args[0];   //...  } } 
like image 64
Patrick Avatar answered Sep 22 '22 00:09

Patrick