Gradual alpha Movie Clip

Hey there guys… a quick (and undoubtedly simple) problem…

I have a button that, when rolled over, causes a certain movie clip to fade out. Then, on roll out, it fades back in (to 50% opacity). The code looks like this:

on (rollOver) {
setProperty(“mc1”, _alpha, “0”);
}
on (rollOut) {
setProperty(“mc1”, _alpha, “50”);
}

Can anyone suggest a way to make it fade out and in gradually ?

Thanks!
Brad

Try something like this using hitTest. Just give your movieclip an instance name of something like “box” for example and apply this script to your button:

onClipEvent (enterFrame) {
	if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
		_root.box._alpha -= 10;
	} else {
		_root.box._alpha += 10;
	}
}

I attached a sameple FLA as well. =)

Howdy…

Same thing as electrongeek did… (A couple of minutes late… :() I would normally delete this, but mine goes with FMX syntax, so check out the difference… There shouldn’t be no actual difference between mine and his… Just check out how the syntax can be different…

mc1._alpha = 50;
mc1.speed = 5;
mc1.onRollOver = function ()
{
	this.onEnterFrame = function ()
	{
		if (this._alpha < 100)
			this._alpha += mc1.speed;
		else
		{
			this._alpha = 100;
			delete this.onEnterFrame;
		}
	}
}

mc1.onRollOut = function ()
{
	this.onEnterFrame = function ()
	{
		if (this._alpha > 50)
			this._alpha -= mc1.speed;
		else
		{
			this._alpha = 50;
			delete this.onEnterFrame;
		}
	}
}

Thank you both electronicgeek & CyanBlue. Both answers were very helpful and so were the files.

One last thing…
CyanBlue, in your download I can see that there is an Action attached to frame 1 of layer MC - but I can’t find the actual script :*( . Therefore, when I insert the code into my file (on a layer named "actions’) the ‘mc1’ instance of my movieclip is not changing. Should I have mentioned that this ‘mc1’ instance of my movieclip is within about 3 levels of parent movieclips?:hangover:

Sorry, please disregard my above script question. I understand now! Thanks again! :slight_smile:

:wink: