Heroes never panic.

Extending AS2 Array

Posted: October 23rd, 2003 | Author: klaut | Filed under: Actionscript | 2 Comments »

According to gSkinner’s post, when you extend an array you must call the superClass constructor in a particular way so that the indefinite amount of arguments get passed along correctly to the parent class:

class ArrayExtended extends Array
{
function ArrayExtended(){
super.constructor.apply(this, arguments);
}
public function someFunc(){
return length;
}

}

Well, that never worked for me… actually that’s very strange because it appears as if it works for some but not for others..

today i came across a post a Tween Pix and the solution that i saw there is working:

class ArrayExtended extends Array
{
function ArrayExtended(){
splice.apply(this, [0, 0].concat(arguments));
}
public function someFunc(){
return length;
}

}

but im still wondering WHY the gskinner’s variant doesn’t work for me??!

UPDATE:
The solution above (the one that works for me) was actually first posted at flashcoders mailing list


2 Comments on “Extending AS2 Array”

  1. 1 Francis Bourre said at 7:58 pm on November 4th, 2003:

    Yes, and here’s the explanation :
    http://chattyfig.figleaf.com/ezmlm/ezmlm-cgi?1:mss:90589:200310:gfdhpdjdimjpaiklabja

  2. 2 klaut said at 8:26 pm on November 4th, 2003:

    thanx Francis. now i get it. :)