Skip to main content
Known Participant
November 9, 2015
Answered

inheriting from array class

  • November 9, 2015
  • 1 reply
  • 618 views

hi, I want to create my array class which extends the functionality of the base array.

I wrote something like this:

package {

       

    public class my_array extends Array {

// (...)

    public function my_array(_long:int) {

            // (...)

            super(_long);

        }

    } // class

   

} // package

in other words, I have to call the super constructor, and since when I declare a new array I specify the lenght of the array, I pass the length of the array to the super constructor.

Nothing wrong so far, but when I try to use my new array, like this:

var test:my_array = new my_array(10);

test[0] = 1;

I get this error:

ReferenceError: Error #1056: Cannot create property 0 on my_array.

    at rob1_fla::MainTimeline/frame1()

then I replaced the 'super' line in the constructor of my class with this one:

this = super(_long);

and now I get this one:

1050: Cannot assign to a non-reference value.

so how do I extend the array class, so I can use the indexes of my new array class?

tnx

This topic has been closed for replies.
Correct answer kglad

make your class dyanamic.

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
November 9, 2015

make your class dyanamic.

Known Participant
November 9, 2015

yup, that worked, tnx!. I also noticed that making it dynamic, even though not extending array class works the same, or, making it dynamic makes it work as an array even though it has nothing to do with array class. I see no point in inheriting from array then, if just by inheritance it will not make it dynamic, or even though not being dynamic will not separate the requested space with the super constructor call

kglad
Community Expert
Community Expert
November 9, 2015

you'll need to extend the array class is you want to treat your new class as an array and use the array class methods and properties.