Here’s what I’d like to do.
Call a function that looks at an existing array and creates a new array.
I don’t want to copy the existing array, but I want to use its length, to populate the new array. I want to be able to name the new array in my function declaration (possible?).
The prefix parameter is used to push existing variables into the new array.
function createNewArray(oldArray:Array, newArray:Array, prefix:String):void {
var arrlength:uint = oldArray.length;
//
for (var i:uint = 0; i<arrlength; i++) {
newArray.push(this[prefix+i]);
}
}
var answer_0:String = "no no no";
var answer_1:String = "blah blah blah";
var answer_2:String = "yeah ok";
// var answers:Array = new Array();
createNewArray(questions, answers, "answer_");
declaring the new Array before calling the function works, I was just wondering if it was possible to skip this step, in order to make the function call/array creation more dynamic.