Convert a String into an Array Using Actionscript 3

Submitted by:Jhon Jhon

Date added:06 June, 2011

Category:ActionScript 3

I was trying to pass an array through SWFObject flashvars and realized it can't be done. Instead you need to use a string for your array, pass it into Flash , then convert it to an array using the actionscript "split" function.

Tags: swfobject

Code Snippet:

//the string to turn into an array
var arrayString:String="1,2,3";

//convert the string to an array using the "," as a divider (aka delimiter)
var newArray:Array= arrayString.split(",")

//convert the array items from strings to numbers
var n=newArray.length;
while (n--) {

//test: to make sure conversion to numbers worked
trace(String(trainCubesArray[0]+1)); //test: result is 2