I have a class that instantiates several other classes and stores them in an array. I figured the easiest way to do this is (simplified code):
package{
public class Main{
private var array:Array=new Array()
public function newClassA(par1:*,...rest:*){
array.push(new ClassA(par1,rest))
}
newClassA(1,2,3)
}
}
(separate class file)
package{
public class ClassA{
public function ClassA(par1:*,...rest:*){
trace("rest = "+rest[0])
}
}
}
(example trace)
rest = 2,3
I run into the obvious problem of the rest parameters being unusable since the entire rest array from newClassA gets stored in the first slot of the rest array for ClassA (as shown in the sample trace)? In my search I found a way around it using apply(), but that won’t work with a constructor (to my knowledge/testing).
How do I get around this problem, or is there a much better way to instantiate the class and add it to an array than the way I have been doing it?
Edit: I think I figured it out. It didn’t occur to me that the proper syntax for accessing an array within an array is myArray*[j].