Copy link to clipboard
Copied
Hi everyone,
I'm trying to create a movie clip with a glow filter on it, and when the mouse gets closer, its glow increases.
Could someone please run me through the code necessary for this, please?
Thanks so much in advance!
Watto
Copy link to clipboard
Copied
use something like:
var gf:GlowFilter = new GlowFilter(0xff0000,1,0,0);
var gmax:int = 64; //<-glow max
var d:int;
stage.addEventListener(MouseEvent.MOUSE_MOVE,blurF);
function blurF(e:MouseEvent):void{
d=somefunctionof((mc.x-e.stageX)*(mc.x-e.stageX)+(mc.y-e.stageY)*(mc.y-e.stageY));
gf.blurX = gf.blurY = gmax/(d+1);
mc.filters = [gf]
}
funciton somefunctionof(d:Number):Number{
//you'll want something that isn't too large when the mouse is distant. but what's too large and what's distant is up to you. you could start with:
return Math.sqrt(d);
or
return Math.log(d);
or even
return Math.log(Math.sqrt(d));
}
Copy link to clipboard
Copied
Hi, this seems super close, but I can't quite work it out, sorry! I can't work out how to change the minimum and maximum glow, and also when the cursor first enters the stage, it goes to maximum glow at first.
I would really appreciate a hand getting it working!
Thank you
Copy link to clipboard
Copied
do you see the blur change depending on distance from mouse to object?
Copy link to clipboard
Copied
(Sorry for the delay in replying!)
It's frustrating that I can't attach the fla, but yes, it works very subtly. I don't understand the maths to make the glow bigger.
I really appreciate the help!
Copy link to clipboard
Copied
that's why i posted that comment in:
funciton somefunctionof(d:Number):Number{
//you'll want something that isn't too large when the mouse is distant. but what's too large and what's distant is up to you. you could start with:
return Math.sqrt(d);
or
return Math.log(d);
or even
return Math.log(Math.sqrt(d));
}