Sunday, July 29, 2007

ChangeColour Actionscript 2 class

I made this class some time ago and I'm still using it whenever I don't have time or creativity to do any other rollOver - rollOut effect; One of my readers (who saw the Spanish-Polish application) asked me about it so, why not sharing the code?

I guess these days I would do it in a different way but still does the job; to use it, just copy and paste the following code into your actionscript editor and save it as

* Version 1
* Movieclip rollOver and rollOut ChangeColour class
* Author: Ernesto Quezada, Overloadstudios (ernesto.quezada(a)
* Date: October 2006
* Description: Gradually changes colour and brightness to a movieclip when rolled over
* and back to its original colour when rolled out
class ChangeColour extends MovieClip {

private var control:Number = -10;
private var addShine:Object;
private var currentState:String;
private var myColour:Color;

// -- Constructor --
private function ChangeColour() {
currentState = "rolledOut";

// -- Events --
private function onRollOver():Void {
currentState = "rolledOver";
this.onEnterFrame = function () {
private function onRollOut():Void {
currentState = "rolledOut";

// -- private functions --
private function checkState():Void {
myColour = new Color(this);
if (currentState == "rolledOver") {
if (control<=100) { control += 10; addShine = {rb:control, gb:control-20, bb:control-50}; } else { addShine = {rb:0, gb:0, bb:0}; } myColour.setTransform(addShine); updateAfterEvent(); } else if (currentState == "rolledOut") { if (control>=10) {
control -= 10;
addShine = {rb:control, gb:control, bb:control};
} else {
delete this.onEnterFrame;

Then put it in a folder called Classes (or wherever your classpath points to) and whenever you want to use it, in the Flash library, right click on a movieclip, select export for actionscript and write ChangeColour as the AS 2.0 class.

I know, I made it 9 months ago and needs a review...



winston8r said...

Very usefull script. thx, However, I kkep getting a message saying: Class not compatable with As2" when I try and fill in the linkage class name in the symbols library.

Ernesto said...

Hi winston8r, are you publishing for flash player 8? or which player?
I will upload an example tomorrow :)