Jump to content
Search Community

opacity question

TheMightyMac test
Moderator Tag

Recommended Posts

Hello! I am having trouble with the starting opacity of an mc. I'm sure it's an easy fix I am overlooking but I don't know what I'm doing wrong. Basically I want to have a button that when you mouse over it an arrow fades in from zero opacity to full opacity and at the same time moves towards the button. My problem is when I first play the movie the arrow is visible on the stage when it should start out invisible. Here's the code I'm using:

 

stop();

import com.greensock.*;

import com.greensock.easing.*;

 

home_mc.buttonMode = true;

 

 

home_mc.addEventListener(MouseEvent.MOUSE_OVER, onOver);

 

 

 

function onOver(e:MouseEvent):void

{

TweenLite.to(home_mc, .25, {scaleX:1.25, scaleY:1.25, ease:Back.easeOut});

TweenLite.from(arrow_mc, 1.25, {alpha:0});

TweenLite.to(arrow_mc, .5, {x:140, overwrite: 0});

}

 

Any help will be greatly appreciated :)

 

Thanks,

Mike

Link to comment
Share on other sites

TweenLite.from() will create a tween from arrow_mc's current alpha to is passed in the vars - initally this will be from 0 to 1. The problem is, if arrow_mc has an alpha of 0 when you rollover, it will tween from 0 to 0; alpha of 0.5 = 0 to 0.5 etc. You could use TweenMax's fromTo() to prevent any mix ups, or just use TweenLite.to() so you always know where you'll end up.

 

You will also need to define arrow_mc's alpha to 0 if you want it to start hidden.

 

arrow_mc.alpha = 0;

function onOver(e:MouseEvent):void
{
TweenLite.to(home_mc, .25, {scaleX:1.25, scaleY:1.25, ease:Back.easeOut});
TweenLite.to(arrow_mc, 1.25, {alpha:1});
TweenLite.to(arrow_mc, .5, {x:140, overwrite: 0});
}

function onOut(e:MouseEvent):void
{
TweenLite.to(arrow_mc, 1.25, {alpha:0});
}

Link to comment
Share on other sites

If you are animating alpha between 0 and 1, it is sometimes a good idea to use greensock's autoAlpha plugin (activated by default for TweenMax). It will automatically toggle visible = false when alpha == 0, and visible = true when it doesn't. It's a great way to get a (slight) increase in performance, as any DisplayObject with visible == true is always 'rendered' by flash, and will still interact with the mouse, firing rollover, mouseover etc events.

 

TweenPlugin.activate([AutoAlphaPlugin]); //activation is permanent in the SWF, so this line only needs to be run once.

// hide the arrow_mc completely
arrow_mc.alpha = 0;
arrow_mc.visible = false;

//fade the arrow in
TweenLite.to(arrow_mc, 1.25, {autoAlpha:1});

// fade the arrow out
TweenLite.to(arrow_mc, 1.25, {autoAlpha:0});

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...