Search code examples
actionscript-3vectorflash-10

How to declare a filled Vector?


I am using Vectors in Flash 10 for the first time, and I want to create it in the same way I used to do with Arrays, e.g:

var urlList : Array = [url1, url2, url3];

I have tried various different methods but none seem to work, and I have settled on the following as a solution:

var urlList : Vector.<String> = new Vector.<String>();
urlList.push(url1, url2, url3);

Is this even possible?


Solution

  • When it doubt, check the AS3 docs. :)

    var urlList : Vector.<String> = new <String>["str1", "str2", "str3"];
    trace(urlList);
    

    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Vector.html#Vector()

    Direct quote of the line I adapted this from in the documentation:

    To create a pre-populated Vector instance, use the following syntax instead of using the parameters specified below:

     // var v:Vector.<T> = new <T>[E0, ..., En-1 ,];
     // For example: 
     var v:Vector.<int> = new <int>[0,1,2,];