Mouse transparency

Code Actionscript 2.0

Instance action

onClipEvent (load) {
this._alpha = 0;
}
onClipEvent (enterFrame) {
smoothness = 2.0;
distancex = _parent._xmouse - this._x;
distancey = _parent._ymouse - this._y;
distance = Math.sqrt(distancex * distancex + distancey * distancey);
this._alpha = 100 - distance / smoothness;
}

Code Actionscript 3.0

square.addEventListener(Event.ENTER_FRAME, enterFrame); square.alpha = 0; function enterFrame(event:Event) { var smoothness = 200; var distancex = mouseX - square.x; var distancey = mouseY - square.y; var distance = Math.sqrt(distancex * distancex + distancey * distancey); event.target.alpha = 1 - distance / smoothness; }

Description

The transparency of the square changes, depending on its distance from the mouse. The variable smoothness determines how gradual the change in transparency will be.

Download

Right click: Flashfile AS 2.0 | Flashfile AS 3.0 | SWF-File


Share