How to bind effect in code in Flex

825 Views Asked by At

I want to add a component into a Viewstack dynamically in flex4. Like code below

 for(var i:int = 0; i < 3; i++)
 {
    var canvas:NavigatorContent = new NavigatorContent();
    canvas.label = "XXX";
    // here I want to add effect to canvas.
    // var effect:Fade = new Fade(canvas);
    // effect.duration = 2000;
    viewStack.addChild(canvas);
}

But the code in comment doesn't play the effect. How can I implement it? Does the canvas have any hideffect or showeffect to Bind?

thanks

2

There are 2 best solutions below

1
Jason Towne On

You can use the NavigatorContent's hideEffect and showEffect properties.

FlexExamples has a good example on how to set these properties using Actionscript.

0
Christofer Dutz On

Well I think the problem is he is creating the Effect Object inside the function. As soon as this function is left, I think there is no reference from the canvas object to the effect object and the GarbageCollection cleans it up. Try explicitly saving a reference to the effect object.