PDA

View Full Version : extending Array in AS3.0



jwopitz
August 8th, 2006, 03:03 PM
I have a class that I am converting from AS2.0 to AS3.0. In AS2 it works perfectly. But in AS3 I am getting a weird error. Here is what I have in the .fla:

var pts:PtManager = new PtManager ();
pts[0] = "point";
trace (pts[0]);
and it gives me this error:

ReferenceError: Error #1056: Cannot create property 0 on com.jwopitz.geom.PtManager.
at Timeline0_74cb4621d598448a6e3c45cb373913/::frame1()

So now look at this. I have a command in the class file that creates and registers a new pt:

public function registerPt (pt:Pt):void {
this.push (pt);
return void;
}
Now if I do this in the .fla it will return length but still no access to the item in the array:

var p:Pt = new Pt (0, 0, 0);//my own pt class ;)
var pts:PtManager = new PtManager ();
pts.registerPt (p);
trace (pts.length) //outputs 1;
trace (pts[0]); //outputs the error

senocular
August 8th, 2006, 03:40 PM
did you make the class dynamic?

jwopitz
August 8th, 2006, 03:49 PM
oh, no I did not. I thought by extending Array that would be assumed by the compiler.

jwopitz
August 8th, 2006, 03:56 PM
ok so making it dynamic fixed that issue. Thanks for that!

I do have a question about being able to pass an unknown number of parameters to the constructor. Since AS3 requires a defined number of parameters (& the default value) how could you create the constructor so that it works like an array?

senocular
August 8th, 2006, 04:09 PM
see
http://www.kirupa.com/forum/showpost.php?p=1911296&postcount=107

jwopitz
August 8th, 2006, 04:19 PM
Great. That fixed it! Thanks so much for the pointers. :beer:

latcho
August 20th, 2009, 09:37 PM
see
http://www.kirupa.com/forum/showpost.php?p=1911296&postcount=107

3 years later: THANK YOU !
Latcho

senocular
August 20th, 2009, 09:58 PM
Don't know why this was in AS 1.0/2.0 (maybe it was before we had a 3.0 forum)
Moving to AS3...

Poco
October 6th, 2011, 05:20 PM
Maaan... I was wondering why it doesn't work.

So 5 years later: thank you!