views:

83

answers:

2

Everywhere I've looked has instructed me to download plugins and addons because they're "superior." I'm just looking for a simple fade in/fade out when a child is added/deleted (if fadein is all I can get, I'll take it.) Here is a function I'm calling...

var trashbagFrame:MovieClip = new menu_trashbag_mc_frame();
trashbagFrame.x = 900;
trashbagFrame.y = 0;

menu_trashbag_mc.addEventListener(MouseEvent.MOUSE_UP, trashbagContent);

function trashbagContent(event:MouseEvent):void {
    if(MovieClip(root).currentFrame == 850) {
    while(MovieClip(root).numChildren > 2)
    {
        MovieClip(root).removeChild(MovieClip(root).getChildAt(MovieClip(root).numChildren - 1));
    }
MovieClip(root).addChild(trashbagFrame);
MovieClip(root).addChild (closeBtn);
}
else {
MovieClip(root).addChild(trashbagFrame);
MovieClip(root).addChild (closeBtn);
MovieClip(root).gotoAndPlay(806);
}
}
A: 

Most likely those sites meant the addons like Tweener and such are more flexible/simple to use when you constantly need transitions.

The ActionScript 3.0 Library has a class called Fade in the fl.transitions package.

import fl.transitions.*;
import fl.transitions.easing.*;

TransitionManager.start(img1_mc, {type:Fade, direction:Transition.IN, duration:9, easing:Strong.easeOut});

https://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/fl/transitions/Fade.html

where

img1_mc

will be the object (in your case the child), that you want to apply the transition.

phwd
Where would I put these? I put them after each function, but nothing happened
steve
I put the code directly after each variable is declared at the top, and when it fades in it doesn't start from 0 opacity, it starts from like 50%...
steve
What exactly are you trying to do ? If you read the AS Ref from the link I placed all the information is there. Reading it you have an object (img1_mc) which will undergo a transition based on the parameters you give it. The parameters for the type of transition (Fade), direction (IN), duration (9s) and the type of easing (Strong.easeOut). To get even simpler you can use the Tween class.var fadeIntween:Tween = new Tween(img1_mc, "alpha", None.easeIn, 0, 1, 9, true);https://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/fl/transitions/Tween.html
phwd
Ah, it does work on regular children. The code I have is a bit complex, so the fade doesn't work on all the children because they've been added/removed multiple times as the user browses the site. Oh well, thanks for your help!
steve
A: 

You could just use an enterFrame to change the property over time. Something like:

var trashbag:MovieClip = new MovieClip();
trashbag.alpha = 0;
addChild(trashbag);
trashbag.addEventListener(Event.ENTER_FRAME, enterFrameHandler);

var closeBtn:MovieClip = new MovieClip();
closeBtn.alpha = 0;
addChild(closeBtn);
closeBtn.addEventListener(Event.ENTER_FRAME, enterFrameHandler);

function enterFrameHandler(e:Event):void 
{
    var targetMC:MovieClip = e.currentTarget as MovieClip;
    if(targetMC.alpha >= 0.9)
    {
        targetMC.alpha = 1;
        targetMC.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
    }
    else
    {
        targetMC.alpha += 5;
    }
}

Hope that sample code helps. I haven't tested it, but the idea works.

TandemAdam