Extending AS2 Array

October 23rd, 2003

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 Responses to “Extending AS2 Array”

  1. Francis Bourre Says:

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

  2. klaut Says:

    thanx Francis. now i get it. :)