• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Movieclip glow increases with mouse/cursor proximity

New Here ,
Oct 03, 2017 Oct 03, 2017

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

TOPICS
ActionScript

Views

343

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 04, 2017 Oct 04, 2017

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));

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 09, 2017 Oct 09, 2017

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 09, 2017 Oct 09, 2017

Copy link to clipboard

Copied

do you see the blur change depending on distance from mouse to object? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 22, 2017 Oct 22, 2017

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2017 Oct 23, 2017

Copy link to clipboard

Copied

LATEST

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));

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines