3

If I am a subclass of an Array, how do I access an element?

class ArrayOfFoo extends Array
{
   public function getFooAt(anIndex : int) : Foo
   {
        return this[anIndex] as Foo;   //  <---- looks for an object attribute (named "0", for example)
   }
}

I could wrap an array instead of subclassing it, however lacking a universal IArray interface, that is less than useful for standard and custom functions expecting an Array.

Vectors do not allow subclassing at all, so they won't help.

Thanks

2
  • If you're subclassing an Array, you need to set the class to dynamic. Commented Mar 16, 2011 at 18:19
  • First off, I assume since you're posting this question that your code snippet does not work. Do you get an error? What is the error? Is it a compile time or run time error? Is this Flex specific code? If so, then you can create a collection that implements ICollectionView. help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/… . Commented Mar 16, 2011 at 18:21

1 Answer 1

6

Unfortunately this is not as straight forward as you think. Check Extending the Array class on Adobe livedocs for the detail method of extending an array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.