I’m playing around with some AS3 for fun atm.
I have two files, I create two boxes with different colors. I have a mouseover function that change the color when the mouse is over the box, and a mouse_out function. How do I go back to the original color in my “MouseOUT” function instead of setting a new color?
Main.as
package {
import flash.display.Sprite;
import flash.events.Event;
public class Main extends Sprite {
public function Main() {
addEventListener(Event.ENTER_FRAME, init);
}
public function init(eve:Event) {
removeEventListener(Event.ENTER_FRAME, init);
var redBox:Box = new Box ("100", "200", "0xFF0000");
var blackBox:Box = new Box ("100", "200", "0x000000");
blackBox.x = redBox.width;
addChild(redBox);
addChild(blackBox);
}
}
}
Box.as
package {
import flash.display.Sprite;
import flash.display.*;
import flash.events.*;
import flash.geom.ColorTransform;
public class Box extends Sprite {
public var box:Shape = new Shape ();
public function Box(boxWidth, boxHeight, boxColor) {
box.graphics.beginFill (boxColor);
box.graphics.drawRect (0, 0, boxWidth, boxHeight);
box.graphics.endFill ();
addChild(box);
addEventListener(MouseEvent.MOUSE_OVER, MouseOVER);
addEventListener(MouseEvent.MOUSE_OUT, MouseOUT);
}
public function MouseOVER(eve:Event) {
var newColor:ColorTransform = box.transform.colorTransform;
newColor.color = 0x00FF00;
box.transform.colorTransform = newColor;
}
public function MouseOUT(eve:Event) {
var newColor:ColorTransform = box.transform.colorTransform;
newColor.color = 0xF00FF0;
box.transform.colorTransform = newColor;
}
}
}