开发者

Subclassing an AS3 Array: how to get array elements (this[0] does not work)?

开发者 https://www.devze.com 2023-02-17 01:23 出处:网络
If I am a subclass of an Array, how do I access an element? class ArrayOfFoo extends Array { public function getFooAt(anIndex : int) : Foo

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 hel开发者_开发知识库p.

Thanks


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消