Why not predefine the params as null? class myClass{ public function myClass(param1 = null, param2 = null, ... param6 = null){ } }
or just use the rest (...) parameter class myClass{ public function myClass(...args){ for(var i:uint = 0; i < args.length; i++){ trace(args[i]); } } } On Thu, Jan 8, 2009 at 10:36 PM, Patrick Matte | BLITZ < pma...@blitzagency.com> wrote: > Well for now I've done this which supports up to 5 arguments but if > anyone's got a better suggestion please tell me... > > var classReference:Object = getDefinitionByName(className); > var object:Object; > switch(array.length) { > case 0: > object = new classReference(); > break; > case 1: > object = new classReference(array[0]); > break; > case 2: > object = new classReference(array[0],array[1]); > break; > case 3: > object = new classReference(array[0],array[1],array[2]); > break; > case 4: > object = new > classReference(array[0],array[1],array[2],array[3]); > break; > case 5: > object = new > classReference(array[0],array[1],array[2],array[3],array[4]); > break; > } > > -----Original Message----- > From: flashcoders-boun...@chattyfig.figleaf.com [mailto: > flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Patrick > Matte|BLITZ > Sent: Thursday, January 08, 2009 7:19 PM > To: Flash Coders List > Subject: [Flashcoders] create object with getDefinition and pass parameters > using apply ? > > I need to create objects using getDefinition and pass parameter to the > constructor but the problem is that the number of parameters can be > different. I tried using apply like this but I can't make it work. > > var classReference:Object = getDefinitionByName(className); > var object:Object = new classReference.apply(this, array); > > Is there any way to do this ? > > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > -- --Joel Stransky stranskydesign.com _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders