views:

581

answers:

3

Hi, I'm removing a component from the WindowedApplication, using removeChildAt(), and want to play an effect (defined within the component, say mx:Resize) which reduces the height of the component (an hbox) to 0 before it is removed.

I was using the removedFromStage event within the component, but it just disappears (without playing the effect). I guess it's being removed before the effect is played. Is there a way to play the effect, which is preferably defined in the component, before the removeChild function completes?

Thanks.

A: 

removedFromStage is going to be fired after the component has been removed (appropriate for cleanup/memory management). Most Flex components have a removedEffect property. This is what you want to use.

Joel Hooks
This is more what I was looking for. I've tried using it in both the Component root node and as a 'setStyle', but in both cases the component quickly resizes then returns to it's original height (and isn't removed). My resize is very basic, and just looks like:<mx:Resize heightFrom="35" duration="100" heightTo="0" id="CloseDown"/>Any thoughts? Thanks.
Ian
A: 

Hello,

Please consult the mx.effects.Resize class help page under Flex Builder, and see the events list.

Basically what you need to do with your code is:

  1. create the resize event.

  2. add an event listener for the effect end

  3. play the effect

  4. when the effect ended you close the window.

The code should look like:

public function close():void
{
    var resize:Resize  = new Resize();
    resize.heightTo  = 0;
    resize.duration  = 500;
    resize.addEventListener(EffectEvent.EFFECT_END, onCloseEffectEndHandler);

    resize.play([this]); 

}

private function onCloseEffectEndHandler(event:EffectEvent):void
{
    PopUpManager.removePopUp(this);
}

NOTE: WHEN YOU SHOW THE WINDOW DO NOT FORGET TO SET THE HEIGHT, ELSE IT WILL REMAIN 0 AND YOU WILL SEE NOTHING!

You can find some nice flex stuff here: TiMeister Blog

Adrian Pirvulescu
A: 

I moved the effect to the parent so:

var contentBox:VBox = new VBox();
var cm:HBox = new Hbox();
cm.setStyle('removedEffect', CloseDown);
contentBox.addChildAt(cm, 0);
//in another function
contentBox.removeChild(0);

This works. When I had the effect in the component itself, this didn't work, alas.

Ian