Need an object to fade out in AS3
So, i have a game, where there is a spawned square, and the goal is to click it, when you click it, it changes locations, as well as colors and sizes. What I want to happen is this: I want my square to fade out instead of just dissapearing and changing locations when clicked. To do this, im assuming that I need to have another identical square on top of it, that fades while the other square changes locations, but I cannot figure out how to have two identical squares, do two seperate things, since I am using AS files, and my timeline and stage are blank, as well as my actions.
Here is my code for the square and everything that it does(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()
{
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() * 700 + (height / 2));
x = square_x;
y = square_y;
trace("X:" + x, "Y:" + y, "Height and Width:" + height);
}
public function changeParameters():void
{
var myColor:ColorTransform = transform.colorTransform;
var colorNumber:Number
colorNumber = Math.round(Math.random() * 15);
trace(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 == 😎 { 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;}
transform.colorTransform = myColor;
trace("Object Clicked");
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);
}
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;
}
}
}
};
Im guessing that I would have it fade out in the changeParameters, because that is what is triggered when the square is clicked. Remember, I want to have it fade out, while there is still another square that changes places, so that the user does not have to wait for it to finish fading before they can click the next square.
In case this is of any importance, here is my document class Game.as:
package
{
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flashx.textLayout.formats.BackgroundColor;
public class Game extends MovieClip
{
public var myTimer:Timer = new Timer(5);
public var square:Square;
public var square2:Square;
public var background:Background;
public function Game()
{
background = new Background();
square = new Square();
square2 = new Square();
addChild ( background )
addChild ( square )
addChild ( square )
square.addEventListener(MouseEvent.CLICK, fl_click);
square2.addEventListener(MouseEvent.CLICK, fl_click);
myTimer.addEventListener(TimerEvent.TIMER, timerListener);
myTimer.start();
}
private function timerListener(e:TimerEvent):void
{
square.edgeCorrect();
}
private function fl_click(event:MouseEvent):void
{
square.changeParameters();
}
}
}
