Be a Supporter!

AS3 fade

  • 213 Views
  • 3 Replies
New Topic Respond to this Topic
Tiki-King
Tiki-King
  • Member since: Jul. 25, 2009
  • Offline.
Forum Stats
Member
Level 02
Programmer
AS3 fade 2011-02-01 15:24:29 Reply

So i have a code where mouse on button makes movieclip visible and mouse out invisible. Now i want to achieve this mc to fade in/out, not just dissapear or show up in a moment.

_mc.visible=false;

_btn1.addEventListener(MouseEvent.MOUSE_OVER, showMc, false, 0, true);
_btn1.addEventListener(MouseEvent.MOUSE_OUT, hideMc, false, 0, true);

function showMc(e:Event):void
{
	_mc.visible = true;
}

function hideMc(e:Event):void
{
	_mc.visible = false;
}

Thank you :)

xKiRiLLx
xKiRiLLx
  • Member since: Feb. 8, 2007
  • Offline.
Forum Stats
Member
Level 09
Game Developer
Response to AS3 fade 2011-02-01 15:29:17 Reply

Create a flag variable that gets toggled on mouse click (or whatever you want). Create an Event.ENTER_FRAME event that increases the alpha when the variable is true and decreases when its false.

Kirk-Cocaine
Kirk-Cocaine
  • Member since: Aug. 17, 2003
  • Offline.
Forum Stats
Moderator
Level 38
Programmer
Response to AS3 fade 2011-02-01 15:30:27 Reply

You can tween it's alpha property, from 1 to 0, either using the built in Tween class, or a more robust tweening package, such as TweenLite.


The water in Majorca don't taste like what it oughta.

| AS3: Main | AS2: Main | Flash Tutorials |

BBS Signature
Tiki-King
Tiki-King
  • Member since: Jul. 25, 2009
  • Offline.
Forum Stats
Member
Level 02
Programmer
Response to AS3 fade 2011-02-01 15:44:58 Reply

It works! Thank you very much everyone :)