Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

inheriting from array class

Explorer ,
Nov 09, 2015 Nov 09, 2015

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

TOPICS
ActionScript
558
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 09, 2015 Nov 09, 2015

make your class dyanamic.

Translate
Community Expert ,
Nov 09, 2015 Nov 09, 2015

make your class dyanamic.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 09, 2015 Nov 09, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 09, 2015 Nov 09, 2015
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines