Reputation: 1664
I am currently being confused by the Vector
class.
I wrote a beautiful XML
to TypedClass parser. Works beautifully and without fault. UNTIL a co-worker noticed we got a Conversion Error for Vector.<Number> to Vector.<*>
.
Every Vector
I've ever tested all extend Vector.<*>
.
Vector.<Sprite>
, Vector.<String>
, Vector.<Point>
, Vector.<Boolean>
, Vector.<TextField>
, Vector.<CustomObject>
, etc etc etc. ALL of them.
<type name="__AS3__.vec::Vector.<String>" base="__AS3__.vec::Vector.<*>" isDynamic="true" isFinal="false" isStatic="false">
<extendsClass type="__AS3__.vec::Vector.<*>"/>
<extendsClass type="Object"/>
<accessor name="length" access="readwrite" type="uint" declaredBy="__AS3__.vec::Vector.<*>"/>
<accessor name="fixed" access="readwrite" type="Boolean" declaredBy="__AS3__.vec::Vector.<*>"/>
</type>
But then when I use describeType on Vector.<Number>
, Vector.<uint>
and Vector.<int>
.
<type name="__AS3__.vec::Vector.<Number>" base="Object" isDynamic="true" isFinal="true" isStatic="false">
<extendsClass type="Object"/>
<constructor>
<parameter index="1" type="uint" optional="true"/>
<parameter index="2" type="Boolean" optional="true"/>
</constructor>
<accessor name="length" access="readwrite" type="uint" declaredBy="__AS3__.vec::Vector.<Number>"/>
<accessor name="fixed" access="readwrite" type="Boolean" declaredBy="__AS3__.vec::Vector.<Number>"/>
</type>
Now I have accounted for these 3 vectors individually as even uint and int does not extend Vector.<Number>
as I would have expected.
And my parsing function works for all types correctly again. But my confusion comes as to WHY this is the case, and why I couldn't find any documentation on the subject.
Upvotes: 0
Views: 468
Reputation: 8468
I asked the same question on the Kirupa forums a few months back, but I cannot for the life of me find the thread.
If I remember this correctly, the Vector.<Number>
, Vector.<int>
, and Vector.<uint>
(but not Boolean
or String
, oddly enough) classes are made to be as fast as possible, so they are written and treated as separate classes by the Flash Player.
As you have noticed, all other Vector classes extend Vector.<*>
and type checking is done a bit differently (which is why Vectors are faster with int, uint, and Number, but Arrays are slightly faster for all other classes)
Anyway, that was the WHY. As for how to get around this issue, I'm afraid you are going to have to pass your vector as untyped to the function you want to use it in:
public function addItem(vector:*, item:*)
{ vector.push(item); }
Upvotes: 1