PDA

View Full Version : testing for color transform


CPedrick
07-03-2008, 05:48 PM
I want to be able to apply a color transformation to each of a number of movie clips each containing a single letter, and then remove the color transformation later based upon a mouse click event.
I have set up the various letters as individual movie clips, each of which listens for the click event, and can use the code shown below to readily apply the transformation to a randomly clicked letter.


public function clickLetter(event:MouseEvent) {

var rOffset:Number; //red offset
var bOffset:Number; //blue offset
rOffset = transform.colorTransform.redOffset + 100;
bOffset = transform.colorTransform.redOffset - 100;
event.currentTarget.transform.colorTransform = new ColorTransform(1, 1, 1, 1, rOffset, 0, bOffset, 0);

} //end function clickLetter


The problem comes if I want to be able to remove the transformation when a particular letter is clicked again.

Is there some way I can test to see if a transformation has been applied?

TIA,
Carolyn

DiamondDog
07-03-2008, 08:28 PM
Maybe use a Boolean variable which is 'true' if the movie clip has been clicked, and 'false' if it hasn't been clicked?

public function clickLetter(event:MouseEvent) {

if(event.currentTarget.clicked != true)
{
var rOffset:Number; //red offset
var bOffset:Number; //blue offset
rOffset = transform.colorTransform.redOffset + 100;
bOffset = transform.colorTransform.redOffset - 100;
event.currentTarget.transform.colorTransform = new ColorTransform(1, 1, 1, 1, rOffset, 0, bOffset, 0);
event.currentTarget.clicked = true; // mark the clip as being clicked
}
else
{
// it's been clicked already, so remove the color transformation
....
....
event.currentTarget.clicked = false; // reset the Boolean
}
} //end function clickLetter

The first time a movieclip is clicked, it's 'clicked' property will be undefined (so that first test will fail, and you'll apply the transformation).
After that, the above should mean that you can toggle the transformation on and off as many times as you wish.

Hope it works!

CPedrick
07-03-2008, 08:37 PM
That worked great!
I had created a workaround where I set the alpha to .9 or 1 to use it as a flag. This is much better.
I'm new to AS3, so I didn't know you could create properties like that on the fly, and I didn't want to have to set up some sort of array to track click state for all the letters.

Thanks very much!!
Carolyn

DiamondDog
07-03-2008, 08:40 PM
That's cool. I'm glad it worked.

I know what you mean. Not many days when AS3.0 doesn't surprise me with something.:)

Dynamic variables I think they're called.