View Full Version : duplicate
bahrami
02-02-2007, 07:10 PM
Hello!
I have a newbee question about duplicate movieclips.
I have a mc lets call it "ball_mc" in my _root.
I need to duplicate it and set the duplicatet version of my mc in random _x positions. I want to duplicate five new virsions of my "ball_mc"
Any suggestion on how the script should look like
Thanx for the help
CyanBlue
02-02-2007, 07:34 PM
You could try this script and see if it helps... ;)
You will need a movieClip, ball_mc, on the stage...
var maxBall:Number = 10;
var minX:Number = 100;
var minY:Number = 100;
var maxX:Number = 400;
var maxY:Number = 300;
this.ball_mc._visible = false;
this.lineStyle(1, 0x000000, 10);
this.beginFill(0x0000FF, 10);
this.moveTo(minX, minY);
this.lineTo(maxX, minX);
this.lineTo(maxX, maxY);
this.lineTo(minX, maxY);
this.lineTo(minY, minX);
this.endFill();
for (var i = 0 ; i < maxBall ; i++)
{
this.ball_mc.duplicateMovieClip("ball" + i + "_mc", this.getNextHighestDepth());
this["ball" + i + "_mc"]._x = randomBetween(minX + this.ball_mc._width, maxX - this.ball_mc._width);
this["ball" + i + "_mc"]._y = randomBetween(minY + this.ball_mc._height, maxY - this.ball_mc._height);
}
function randomBetween(low:Number, high:Number)
{
return Math.floor(Math.round(Math.random() * (high - low))) + low;
}
bahrami
02-02-2007, 08:28 PM
OOOh man, so much code, I just wanted to learn the basics of duplicateMovieClip,.,
I canīt understand all your code, tryed but I just couldnīt,.,.
Can you describe a little bit easie
CyanBlue
02-02-2007, 09:06 PM
Um... How about this one??? (I don't know how simpler it can be...)
// Duplicate the ball_mc onto the stage...
this.ball_mc.duplicateMovieClip("ball1_mc", this.getNextHighestDepth());
// Set the random _x location for the ball1_mc by calling randomBetween() function
this.ball1_mc._x = randomBetween(50, 250);
// Set the random _y location for the ball1_mc by calling randomBetween() function
this.ball1_mc._y = randomBetween(50, 150);
// Function randomBetween()
function randomBetween(low:Number, high:Number)
{
// This function receives high and low numbers as arguments
// and returns the random value between two values...
return Math.floor(Math.round(Math.random() * (high - low))) + low;
}
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.