I think your code won't center correctly does it? Don't know if []
syntax is slower than creating a local var fisrt, but just in case added
it.
function center(ob1:MovieClip, ob_ar:Array) {
var x:Number = ob1._x - (ob1._width/2);
var y:Number = ob1._y;
for (var i = 0; i<ob_ar.length; i++) {
var mc : MovieClip = on_ar[i];
mc._x = x + (mc._width/2);
mc._y = y + (mc._width/2);
}
}
Top of my head, didn't test it.
Ben Smeets
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Alistair
Colling
Sent: vrijdag 11 mei 2007 13:41
To: [email protected]
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]);
_______________________________________________
[email protected]
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
This e-mail and any attachment is for authorised use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be copied,
disclosed to, retained or used by, any other party. If you are not an intended
recipient then please promptly delete this e-mail and any attachment and all
copies and inform the sender. Thank you.
_______________________________________________
[email protected]
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