user2817200
user2817200

Reputation: 1117

ActionScript 3 .alpha property not working

I have three movie clips: 'instructions', 'uelButton' and 'uelHover'. The animation starts off with uelHover not visible (alpha is 0). When I hover over uelButton, I want instructions to dissapear and uelHover to fade in. When I hover off of uelButton, I want uelHover to dissapear and instructions to fade in again. This is my actionscript:

uelHover.alpha = 0;

uelButton.addEventListener(MouseEvent.MOUSE_OVER, uelButtonHovered);

uelButton.addEventListener(MouseEvent.MOUSE_OUT, uelButtonOut);

var tweenA:Tween;

function uelButtonHovered(evt:MouseEvent) { //hover over button
    if (tweenA.isPlaying) {
        tweenA.stop(); //stop tween if it is in the middle of a tween
    }

    instructions.alpha = 0; //remove instructions

    var tweenA:Tween = new Tween(uelHover, "alpha", Regular.easeIn, 0, 1.0, 8, false); //make uelHover fade in
}

function uelButtonOut(evt:MouseEvent) {

        if (tweenA && tweenA.isPlaying) {
        tweenA.stop(); //if uelHover is still fading in, stop the tween so that we can make it's alpha property = 0 in the next line
    }

    uelHover.alpha = 0; //make uelHover disappear
    instructions.alpha = 1; //make instructions appear
}

The problem is, when I hover over and off of uelButton really fast, the instructions movieclip and uelHover movieclip both are on the screen when uelHover is not supposed to be there. Same thing happens if I hover over, off and then hack over uelButton really quickly. Any idea why?

Upvotes: 0

Views: 759

Answers (1)

AndySavage
AndySavage

Reputation: 1769

In uelButtonHovered you are declaring tweenA inside the scope of the function, this is not the same as the other tweenA you have declared outside of your function. The call to stop tweenA in uelButtonOut is not calling stop on the correct tween. The tween will continue top update alpha on uelHover after you have set it to 0 - effectively overwriting your change.

Upvotes: 1

Related Questions