Grey is gooooood
Anyway, to begin we need something to turn grey So go ahead and draw something, import something or generally just make something into a movie-clip within the AS3 flash document. Why not instance name it as “Object” or something…
Now, the fun bit:
1 2 3 4 5 | import flash.events.MouseEvent; import flash.display.MovieClip; Object.addEventListener(MouseEvent.ROLL_OVER, makeGreyscale) Object.addEventListener(MouseEvent.ROLL_OUT, makeColour) |
So, when the Object movie-clip is rolled over with the mouse it triggers the makeGreyscale function and upon roll out the makeColour function is called.
1 2 3 4 5 6 | function makeGreyscale(evt:MouseEvent){ greyscale(Object) } function makeColour(evt:MouseEvent){ colour(Object) } |
Here we simply pass into the function the arguments from the listener then call two more functions which will actually do the work.
1 2 3 4 5 6 7 8 9 10 11 12 13 | function greyscale(Object:MovieClip){ var b:Number = 1 / 3; var c:Number = 1 - (b * 2); var matrix:Array = [c, b, b, 0, 0, b, c, b, 0, 0, b, b, c, 0, 0, 0, 0, 0, 1, 0]; var matrixFilter:ColorMatrixFilter = new ColorMatrixFilter(matrix); Object.filters = [matrixFilter]; } function colour(Object:MovieClip){ Object.filters = []; } |
And all in all you get:









