Reputation: 105
I want to pass to a function an uncertain number of movieclips, sth like this
function Test(...args)
{
for(var item in args){
item.x = 100;
}
}
But using this method didn't work, any solution?
Upvotes: 0
Views: 193
Reputation: 39456
You're almost there, you just need to use a for each
loop for your example to work correctly:
function Test(...args)
{
for each(var item:MovieClip in args)
// ^^^^
{
item.x = 100;
}
}
Better however would be to accept an Array
or Vector
holding the MovieClips. This will greatly improve readability of your code later on:
function Test(list:Vector.<MovieClip>)
{
for each(var item:MovieClip in list)
{
item.x = 100;
}
}
Upvotes: 4
Reputation: 12966
Use arguments
; see the Adobe Reference docs (for AS3), the MDN (for JS) or this example jsfiddle (for a working example).
[NB: question originally tagged as JS, leaving javascript/jsfiddle in there for reference]
Upvotes: 0