1

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

midhunhk
  • 5,560
  • 7
  • 52
  • 83
user498151
  • 151
  • 1
  • 5

2 Answers2

2

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

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

Jason Towne
  • 8,014
  • 5
  • 54
  • 69
  • 3
    minor detail: he's not using a Canvas, but a spark.components.NavigatorContent, which he happened to call `canvas`. Nonetheless, the AS3 code you provided works the same since they both inherit from UIComponent. – merv Aug 02 '11 at 16:20
1

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.

Christofer Dutz
  • 2,305
  • 1
  • 23
  • 34