Copy link to clipboard
Copied
I have an object in my library that I spawned onto my stage using addChild, and i have that item run through a function, to give it many random properties, I want to duplicate this object so that the duplicate has the same random properties that i retrieved. The reason I want a duplicate, is because when the user clicks the original, it changes locaitons, I want the duplicate to stay back and fade out as the original changes places, I then want a new duplicate to repeat this process of fading out when the item is clicked. Basically, it is all for looks.
Here is my constructor code for my object that i want duplicated ( a square ) Square.as:
package
{
import flash.geom.ColorTransform;
import flash.display.MovieClip;
public class Square extends MovieClip
{
var score:Number = 0;
public var square_x:Number;
public var square_y:Number;
public var square_height:Number = 0;
public function Square():void
{
height = Math.round(Math.random() * 160 + 50);
width = height;
square_height = height;
square_x = Math.round(Math.random() * 385 + (width / 2));
square_y = Math.round(Math.random() * 655 + (height / 2));
x = square_x;
y = square_y;
trace("X:" + x, "Y:" + y, "Height and Width:" + height);
}
public function changeParameters():void
{
//Fading should occur here
var myColor:ColorTransform = transform.colorTransform;
var colorNumber:Number
colorNumber = Math.round(Math.random() * 25);
trace("Color:" + colorNumber)
if(colorNumber == 1) { myColor.color = 0xCEEB5A;}
if(colorNumber == 2) { myColor.color = 0xF38612;}
if(colorNumber == 3) { myColor.color = 0x31A915;}
if(colorNumber == 4) { myColor.color = 0x590FE3;}
if(colorNumber == 5) { myColor.color = 0x741004;}
if(colorNumber == 6) { myColor.color = 0x458AD9;}
if(colorNumber == 7) { myColor.color = 0xC28460;}
if(colorNumber == 8) { myColor.color = 0x880AAA;}
if(colorNumber == 9) { myColor.color = 0xEFED70;}
if(colorNumber == 10) { myColor.color = 0x49BDB8;}
if(colorNumber == 11) { myColor.color = 0x71E02A;}
if(colorNumber == 12) { myColor.color = 0x543BD3;}
if(colorNumber == 13) { myColor.color = 0xEA26F2;}
if(colorNumber == 14) { myColor.color = 0x723A4D;}
if(colorNumber == 15) { myColor.color = 0x207D1A;}
if(colorNumber == 16) { myColor.color = 0xD15CBD;}
if(colorNumber == 17) { myColor.color = 0x99FF00;}
if(colorNumber == 18) { myColor.color = 0xFF9966;}
if(colorNumber == 19) { myColor.color = 0x99FF66;}
if(colorNumber == 20) { myColor.color = 0xFF66CC;}
if(colorNumber == 21) { myColor.color = 0x663399;}
if(colorNumber == 22) { myColor.color = 0x00CCCC;}
if(colorNumber == 23) { myColor.color = 0xFF9900;}
if(colorNumber == 24) { myColor.color = 0xFF3333;}
if(colorNumber == 15) { myColor.color = 0xF7F12D;}
transform.colorTransform = myColor;
height = Math.round(Math.random() * 160 + 50);
width = height;
square_x = Math.round(Math.random() * 385 + (width / 2));
square_y = Math.round(Math.random() * 655 + (height / 2));
if (square_x + (width/2) > 480)
{
edgeCorrect();
square_x = square_x - 25;
}
if (square_y + (height/2) >750)
{
edgeCorrect();
square_y = square_y - 25;
}
if (square_x + (width/2) > 480)
{
edgeCorrect();
square_x = square_x - 25;
}
if (square_y + (height/2) >750)
{
edgeCorrect();
square_y = square_y - 25;
}
x = square_x;
y = square_y;
score = score + 1;
trace("Score:" + score);
//I want the new duplicate to have all of the properties above^ and fade out at the very beginning of the function.
}
public function edgeCorrect():void
{
if (square_x + (width/2) > 480)
{
square_x = square_x - 10;
}
if (square_y + (height/2) >750)
{
square_y = square_y - 10;
}
if (x + (width/2) > 480)
{
x = x - 10;
}
if (y + (height/2) >750)
{
y = y - 10;
}
}
}
};
I need to add a duplicate each time so that it can finish fading all the way before it changes locations, but I cant have a delay between the click and the location change. I could possible removeChild once it finishes fading so I dont have tons of children?
Sorry if this is confusing, I wasn't sure how to explain it.
Copy link to clipboard
Copied