Best way in flash mx

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:

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…

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.

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…

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

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.

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

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…

nvm i was too late…:frowning:

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