# Pass rest parameters to a constructor

**URL:** <https://forum.kirupa.com/t/pass-rest-parameters-to-a-constructor/318673>\
**Category:** flash\
**Created:** [January 27, 2011, 12:08am UTC](https://forum.kirupa.com/t/pass-rest-parameters-to-a-constructor/318673 "2011-01-27T00:08:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewlong](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@andrewlong](https://forum.kirupa.com/u/andrewlong)\
**Post date:** [January 27, 2011, 12:08am UTC](https://forum.kirupa.com/t/pass-rest-parameters-to-a-constructor/318673/1 "2011-01-27T00:08:25Z")

</div>

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):

```auto
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].
