3 Replies Latest reply on Aug 6, 2010 4:31 PM by Flex harUI

    Vector Question

    smagfx2

      If I have a method like this:

       

       

      private function operateOnVector(v:Vector.<Object>):void
      

       

       

      and I pass that method (at runtime) something that isn't Vector.<Object>, I get the following error. Even if that type extends the type of the vector.

       

       

      TypeError: Error #1034: Type Coercion failed: cannot convert __AS3__.vec::Vector.<com.example::SomeClass>@1a1de6a1 to __AS3__.vec.Vector.<Object>
      

       

       

      But, if I change the method so that it takes Vector.<*> like this:

       

       

      private function operateOnVector(v:Vector.<*>):void
      

       

       

      Then it works fine at runtime.

       

      All of the above was done by passing an untyped variable to the function which happened to be a certain type of vector. But if I wanted to take advantage of the compile time type checking I get errors like this:

       

       

      1067: Implicit coercion of a value of type __AS3__.vec:Vector.<com.example:SomeClass> to an unrelated type __AS3__.vec:Vector.<*>.
      

       

       

      Even though that is OK at runtime.

       

      So, the question is: Why is there a compile time error for passing a 'typed vector' (i.e. Vector.<SomeClass>) to a method that takes an 'untyped vector' (i.e. Vector.<*>) when it works fine at runtime?

       

      (EDIT: Yes, I know about the global Vector function: http://help.adobe.com/en_US/AS3LCR/Flash_10.0/package.html#Vector())