# MX: proximity with alpha

**URL:** https://forum.kirupa.com/t/mx-proximity-with-alpha/29881
**Category:** flash
**Created:** [September 1, 2003, 1:54pm UTC](https://forum.kirupa.com/t/mx-proximity-with-alpha/29881 "2003-09-01T13:54:50Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![wilma](https://avatars.discourse-cdn.com/v4/letter/w/bbe5ce/32.png) [@wilma](https://forum.kirupa.com/u/wilma)
#### Post date: [September 1, 2003, 1:54pm UTC](https://forum.kirupa.com/t/mx-proximity-with-alpha/29881/1 "2003-09-01T13:54:50Z")

</div>

Hi does anyone know how to create the following - a mc with inertia which chases the mouse pointer, the closer it gets to the pointer the more it fades out??

i can do the mouse follow with inertia and i can do the alpha bit but i just don’t know how to combine them.

does anyone know of the missing link??

regards

wilma

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 1, 2003, 1:56pm UTC](https://forum.kirupa.com/t/mx-proximity-with-alpha/29881/2 "2003-09-01T13:56:14Z")

</div>

well what do you have so far?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 1, 2003, 2:00pm UTC](https://forum.kirupa.com/t/mx-proximity-with-alpha/29881/3 "2003-09-01T14:00:04Z")

</div>

[AS]fadeSpd = 2;

\_root.onEnterFrame = function() {  
if (this.hitTest(\_root.\_xmouse, \_root.\_ymouse, true)) {

\_root.bar4.\_alpha -= fadeSpd;  
\_root.bar4.\_x += ((\_root.\_xmouse-\_root.bar4.\_x)/20);

```
}

```

}[/AS]

it fades out, but it has no relation to where the mouse is…!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 1, 2003, 2:20pm UTC](https://forum.kirupa.com/t/mx-proximity-with-alpha/29881/4 "2003-09-01T14:20:18Z")

</div>

ok, well since this is all happening for \_root.bar4, you might as well just put the onEnterFrame on it. Not quite sure what the \_root hittest is for… because you only want this to happen if the mouse is over the movie? … Ill ignore that for now since its not that important to the fading.

Basically, all you need to do is just figure out how far away your bar4 is from the mouse and set its alpha to that. if the ba is 4 px away, setting its alpha to 4 would make it almost invisible. Further away, at 100 px is fully visible. visble when far, not so much when close. And thats all based on the difference of the \_x value and the \_xmouse - somethign also used in the movement. So with that we can get something like:

```auto
fadeSpd = 2;
_root.bar4.onEnterFrame = function() {
	var x_difference = this._parent._xmouse - this._x;
	this._alpha = Math.abs(x_difference);
	this._x += x_difference/20;
};

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 1, 2003, 2:38pm UTC](https://forum.kirupa.com/t/mx-proximity-with-alpha/29881/5 "2003-09-01T14:38:38Z")

</div>

I’m liking your work…

Math.abs…??? this bit is controlling the fade? whats it telling the flash player to do???

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 1, 2003, 2:56pm UTC](https://forum.kirupa.com/t/mx-proximity-with-alpha/29881/6 "2003-09-01T14:56:12Z")

</div>

Math.abs prevents a value from being negative. If a value is negative, it makes it positive. This is for when the mouse is on the left side of the clip. Then, the x\_difference is a negative number and you wouldnt want the \_alpha going negative but back up, so MAth.abs makes the negative go positive. The \_alpha, though, is just based on the x\_difference

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 1, 2003, 3:03pm UTC](https://forum.kirupa.com/t/mx-proximity-with-alpha/29881/7 "2003-09-01T15:03:17Z")

</div>

every day’s a school day…

thanks for that senocular.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 1, 2003, 3:10pm UTC](https://forum.kirupa.com/t/mx-proximity-with-alpha/29881/8 "2003-09-01T15:10:24Z")

</div>

welcome 🙂
