Search code examples
apache-flexflex4flex-spark

How to set the open and close effect animation of a pop up?


Is there a way to set the effect (default effect) of a pop up using the PopUpManager?

For example, let's say I have created an MXML component and I want that component to zoom in (half size) and rotate 360 degrees on the x, y or z axis. How would I assign this effect to play when I call PopUpManager.addPopUp() or createPopUp()?


Solution

  • You have to apply effects to the window at time of pop-up and close.

    private var win:TitleWindow;
    
    private function addWindow():void{  
        win = new TitleWindow();
        win.addEventListener(CloseEvent.CLOSE, onClose);
        PopUpManager.addPopUp(win, this);
        PopUpManager.centerPopUp(win);
        var scale:Scale = new Scale(win);
        ... set scale properties for cool zoom in
        scale.addEventListener(EffectEvent.EFFECT_END, onZoomInComplete);
        scale.play();
    }
    
    private function onClose(event:CloseEvent):void{
        var scale:Scale = new Scale(win);
        ... set scale properties for cool zoom out
        scale.addEventListener(EffectEvent.EFFECT_END, onZoomOutComplete);
        scale.play();
    }
    
    private function onZoomInComplete(event:EffectEvent):void{
        //Depending on what effects you apply, you may need to re-center the popup 
        //after the zoom in effect is over.. may not need this though
        PopUpManager.centerPopUp(win);
    }
    
    private function onZoomOutComplete(event:EffectEvent):void{
        PopUpManager.removePopUp(win);
    }