I am trying to use the new Vector class introduced in Flash 10. Tried compiling the code using mxmlc but am getting this error message:

Error: Type was not found or was not a compile-time constant: Vector.

public var selectedRoutes:Vector.<Route>;
  1. What could be the problem?
  2. What is the general consensus about the viability of using this feature?
  3. Can you do introspection of the Vector with describeType and get the type the Vector contains at runtime?
+1  A: 

At a guess, you are compiling for FP9 instead of FP10, or perhaps against an older version of the SDK. Make sure everything is up to date.

The Vector type is more performant than using an Array and casting entries to the desired type.

I can't help feeling that they had to hack the compiler to make it work though. The generic-style syntax is valid only for the Vector type, and not a general language feature, which sucks.

If you need the performance or like the type-safety of using the Vector class then it's worth it.

I don't know what describeType gives you back on a Vector type. Why don't you give it a whirl?

Ah! I just didn't set <target-player> in the flex config. Helpful link is I just ended up using a local config. Thanks. I'll go try out describeType.
+1  A: 

I tried a describeType on a Vector declaration:


The result was:

<type name="AS3.vec::Vector.&lt;components::Route>" base="Class" isDynamic="true" isFinal="false" isStatic="true">
<extendsClass type="Class"/>
<extendsClass type="Object"/>
<accessor name="prototype" access="readonly" type="" declaredBy="Class"/>
<factory type="AS3.vec::Vector.&lt;components::Route>">
<extendsClass type="AS3.vec::Vector.&lt;
<extendsClass type="Object"/>
<accessor name="fixed" access="readwrite" type="Boolean" declaredBy="AS3.vec::Vector.&lt;>"/>
<accessor name="length" access="readwrite" type="uint" declaredBy="AS3.vec::Vector.&lt;

So, yes, it does provide the type information. You can pick it out from either the type tag's name or from the factory tag's type.

Good work... +1