# Best way in flash mx

**URL:** <https://forum.kirupa.com/t/best-way-in-flash-mx/10848>\
**Category:** Uncategorized\
**Created:** [January 8, 2003, 8:23am UTC](https://forum.kirupa.com/t/best-way-in-flash-mx/10848 "2003-01-08T08:23:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimw00d](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@jimw00d](https://forum.kirupa.com/u/jimw00d)\
**Post date:** [January 8, 2003, 8:23am UTC](https://forum.kirupa.com/t/best-way-in-flash-mx/10848/1 "2003-01-08T08:23:29Z")

</div>

I’ve seen lots of threads on achieving an alpha fade effect using actionscript. I want to be able to adjust the alpha of an Mc using a button instance.

I’ve experimented with a few techniques using loops and hitTest but at the moment on mouseOver for example the alpha only increases the once until the mouse is taken away and placed over the button again. Obviously I need to achieve a continual evaluation of the mouse position or hitTest in order to achieve a continuous fade effect.

Also how would I ensure that a Mc faded out when the mouse comes away from the button.

I guess what I am asking for is a way of creating a fade in and out on a Mc with a remote button.

Any ideas? I’m sure there are

Regards:rambo:

---

<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:** [January 8, 2003, 8:29am UTC](https://forum.kirupa.com/t/best-way-in-flash-mx/10848/2 "2003-01-08T08:29:03Z")

</div>

Well an on (rollOver) is only per time you rollOver. What you would need for gradual is to have an enterFrame thing going on.

To do this your button will first have to be a movie clip.

Then on that movie clip you would apply these actions…

```auto
on (rollOver) {
	this.onEnterFrame = function() {
		this._alpha += 5;
		if (this._alpha>=100) {
			this._alpha = 100;
			delete this.onEnterFrame;
		}
	};
}
on (rollOut) {
	this.onEnterFrame = function() {
		this._alpha -= 5;
		if (this._alpha<=0) {
			this._alpha = 0;
			delete this.onEnterFrame;
		}
	};
}

```

What this does is… onRollOver it starts an onEnterFrame handler, which will keep updating the code when the movieclip enters the frame (repeatedly that is). So it will increase by 5 until it gets to 100, when it gets there it will stay there and then delete the onEnterFrame so as to preserve CPU resources.

Next is the onRollOut, same method as the onRollOver, but subtracts 5 from the \_alpha. And waits until it gets to 0 then deletes the onEnterFrame.

---

<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:** [January 8, 2003, 8:33am UTC](https://forum.kirupa.com/t/best-way-in-flash-mx/10848/3 "2003-01-08T08:33:14Z")

</div>

Or for easier updating you can use variables to set the speed, high alpha number and low alpha number, then the default alpha on startup, like this…

```auto
onClipEvent (load) {
	highMax = 100;
	lowMax = 30;
	speed = 5;
	this._alpha = lowMax;
}
on (rollOver) {
	this.onEnterFrame = function() {
		this._alpha += speed;
		if (this._alpha>=highMax) {
			this._alpha = highMax;
			delete this.onEnterFrame;
		}
	};
}
on (rollOut) {
	this.onEnterFrame = function() {
		this._alpha -= speed;
		if (this._alpha<=lowMax) {
			this._alpha = lowMax;
			delete this.onEnterFrame;
		}
	};
}

```

---

<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:** [January 8, 2003, 8:42am UTC](https://forum.kirupa.com/t/best-way-in-flash-mx/10848/4 "2003-01-08T08:42:40Z")

</div>

How would a remote button, or Mc posing as a button, work in this case to create the effect you describe on a different Mc on the stage?

So I would have two Mcs on the stage, (1)-Mc posing as a button to create the fade in and fade out on (2)-the Mc to be faded in and out.

---

<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:** [January 8, 2003, 8:43am UTC](https://forum.kirupa.com/t/best-way-in-flash-mx/10848/5 "2003-01-08T08:43:57Z")

</div>

change “this” which targets the clip the actions are on to “\_root.yourClip” which targets another movieclip on the \_root timeline with the instance name “yourClip” (no quotes).

---

<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:** [January 8, 2003, 8:47am UTC](https://forum.kirupa.com/t/best-way-in-flash-mx/10848/6 "2003-01-08T08:47:13Z")

</div>

i’m guessing here, but how bout changing the ‘this’ 's into the other mc instance name…!? maybe i’llt ry it and tell you if it works…

---

<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:** [January 8, 2003, 8:48am UTC](https://forum.kirupa.com/t/best-way-in-flash-mx/10848/7 "2003-01-08T08:48:11Z")

</div>

nvm i was too late…☹

---

<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:** [January 8, 2003, 8:50am UTC](https://forum.kirupa.com/t/best-way-in-flash-mx/10848/8 "2003-01-08T08:50:13Z")

</div>

Alrighty, I am off to bed, 3:50am here.
