You're welcome Ali :)

By making more sense I didn't particularly meant clarity, but ease of use.
For example, if you're calling this function from method(s)that hardcode the
passed clips like in your example, then using arguments makes sense. 
But what if you're dynamically retrieving those clips with some code,
possibly including some and excluding others? In that case, sticking them
into an array while you're retrieving them makes more sense. And then all
you need to do is pass that array. 

Just as a very rough example -

var myMC = containingClip.firstOne;
var clips:Array
for (var i in containingClip){
   if (containingClip[i]._name.indexOf("center") > -1){
    clips.push(containingClip[i]
  }
}

center(myMC, clips)

Similarly (and I'm straying a bit off topic here, so I hope you don't mind)
when you're passing a variable number of arguments as options, it's easier
to create an options object first and pass that instead of loads of
arguments:
 var options:Object = {}
 options.delay = 500;
 options.html = true;
 options.follow = true;

 Tooltip.show("Tooltip Text", options)


Does that make any sense? 

Karina


> -----Original Message-----
> From: Alistair Colling [mailto:[EMAIL PROTECTED] 
> Sent: 11 May 2007 16:37
> To: flashcoders@chattyfig.figleaf.com
> Subject: Re: [Flashcoders] Quick syntax q: how to write a 
> function thatcanreceive an undefined number of parameters
> 
> Thanks Karina this is the sort of thing I was looking for, as 
> you say it may be clearer to code this fn the way I initially 
> said but I was interested in how to code this another way so 
> thanks for helping me.  
> One tiny typo, before someone else does-
> > for (var i = 1; i<arguments.length; i++)
> Thanks again :)
> Ben, thanks for your help too, I hadn't thought of only using 
> the square brackets to make the code more efficient.
> 
> Ali
> 
> 
> 
> 
> On 11 May 2007, at 15:32, Karina Steffens wrote:
> 
> > The parameters received by a function are automatically stored in a 
> > built-in array called "arguments". So you can do something 
> like this:
> >
> > public static function center(obj1:Object) {
> >     var targetX:Number = ob1._x;
> >     var targetY:Number = ob1._y;
> >             for (var i = 1; i<ob_ar.length; i++) {
> >                     arguments[i]._x = targetX+(ob1._width/2);
> >                     arguments[i]._y = targetY+(ob1._width/2);
> >             }
> >     }       
> > }
> >
> > Btw, obj1 doesn't have to be passed seperately either - you can use 
> > var targetX:Number = arguments[0]._x; - but there's no 
> reason to do so 
> > in your code, and this way the method is a bit more clear.
> >
> > The only caveat is that, depending on the rest of your code, if you 
> > have to pass an unknown number of movie clips, there's a 
> chance your 
> > original function might actually make more sense...
> >
> > Cheers,
> > Karina
> >
> >
> >
> >
> >
> >> -----Original Message-----
> >> From: Alistair Colling [mailto:[EMAIL PROTECTED]
> >> Sent: 11 May 2007 12:41
> >> To: flashcoders@chattyfig.figleaf.com
> >> Subject: [Flashcoders] Quick syntax q: how to write a 
> function that 
> >> canreceive an undefined number of parameters
> >>
> >> Hi there, just a quick syntax question, I want to receive 
> a function 
> >> that will centre the position of all objects passed to that of the 
> >> first object passed but the number of objects passed may 
> vary. This 
> >> is the syntax I am currently using, is this the best way to do it?
> >> Thanks for any comments in advance :) Ali
> >>
> >> //ob1 is the object that the objects in the array centre 
> themselves 
> >> to public static function center(ob1:Object,
> >> ob_ar:Array) {
> >>            var targetX:Number = ob1._x;
> >>            var targetY:Number = ob1._y;
> >>            for (var i = 0; i<ob_ar.length; i++) {
> >>                    ob_ar[i]._x = targetX+(ob1._width/2);
> >>                    ob_ar[i]._y = targetY+(ob1._width/2);
> >>            }
> >>    }
> >>
> >> center(myMC, [myMC2, myMC3, myMC4]);
> >>
> >>
> >>
> >> _______________________________________________
> >> Flashcoders@chattyfig.figleaf.com
> >> To change your subscription options or search the archive:
> >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >>
> >> Brought to you by Fig Leaf Software
> >> Premier Authorized Adobe Consulting and Training 
> >> http://www.figleaf.com http://training.figleaf.com
> >>
> >
> > _______________________________________________
> > Flashcoders@chattyfig.figleaf.com
> > To change your subscription options or search the archive:
> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >
> > Brought to you by Fig Leaf Software
> > Premier Authorized Adobe Consulting and Training 
> > http://www.figleaf.com http://training.figleaf.com
> >
> 
> 
> _______________________________________________
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> 
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
> 

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to