Search code examples
actionscriptfadeinfadefadeoutmovieclip

stop fade in out on a movieclip actionscript 2


I'm trying to stop fading in/out my movieclip.

I'll explain: I've integrated my swf in an HTML page with a dropdown list. When i choose an item from this list a javascript function it's called.This function execute a callback to a function in my swf file that fade in/out an image drawn at runtime (depending on the item selected in the dropdown list). When I choose another element I want the previuos item stops fading and the new starts.

This is my fading function:

function fadeIn(h){
if (eval(h)._alpha<100) {
    eval(h)._alpha += 20;
}
else {
    clearInterval(fadeInterval);
    setTimeout(startOut, 500, h);
}
}

function fadeOut(h) {
if (eval(h)._alpha>0) {
    eval(h)._alpha -= 20;
} else {
    clearInterval(fadeInterval);
    setTimeout(startIn, 100, h);
}
}

function startOut(h) {
fadeInterval = setInterval(fadeOut, 1, h);
}

function startIn(h){
fadeInterval = setInterval(fadeIn, 1, h);
}

function flashing(h){   
var bname;
bname = "planGroup.singleObject." + h;
eval(bname)._alpha = 0;
fadeInterval = setInterval(fadeIn, 1, bname);
}

I tried with clearInterval(fadeInterval), but this doesn't always work, tried with my_mc.stop() but this doesn't work either.

I tried also to set a variable count that execute the fading olny 5 times, and this work unless I change the item in the drowpdown list before the function complete.

Any ideas?? Hope it was clear!

Thanks


Solution

  • If anyone cares i solved with the Tween class!! All those functions were replaced by one line of code:

    function fadeTo(clipName, fadeValue){
        new mx.transitions.Tween(eval(clipName), "_alpha", mx.transitions.easing.Regular.easeOut, eval(clipName)._alpha, fadeValue, 1, true);
    }