How to declare a filled Vector?

7.9k views Asked by At

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?

2

There are 2 answers

3
AudioBubble On BEST ANSWER

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,];
5
Sean Fujiwara On

You coerce an array to a Vector:

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