Here are two utility functions that I use to handle popups.  One will
center the popup, the other will align it to the top, right edge.

It was a lot of trial and error to get something which worked all the
time in Flex.  Not sure why such an simple, common task was so
painful.  Note that Flex has a centerPopup function call in the API,
but it is unreliable.

class Util {
    public static var singleton : Util = new Util();

    public static function showPopUpCentered(windowClass:Object,
modal:Boolean, initVars:Object):Object {
        var popup = mx.managers.PopUpManager.createPopUp( _root,
windowClass, modal, initVars);
        popup.centerPopUp( MovieClip(mx.core.Application.application)
);
        return popup;
    }

    public static function showPopUpRightMost(windowClass:Object,
modal:Boolean, initVars:Object):Object {
        var popup = mx.managers.PopUpManager.createPopUp( _root,
windowClass, modal, initVars);
        popup.addEventListener("creationComplete", singleton,
"moveRightMost");
        return(popup);
    }

    public function creationComplete(event) {
        event.target.move((mx.core.Application.application.tabStack ==
undefined ? mx.core.Application.application.width :
(mx.core.Application.application.tabStack.width +
mx.core.Application.application.tabStack.x)) - event.target.width,
mx.core.Application.application.tabStack == undefined ? 0 :
mx.core.Application.application.tabStack.y);
    }
}

Notes on showPopUpRightMost:

1) You have to wait until the popup is fully created before you can
use it's size.  I used a creationComplete event listener on a
singleton of the Util class.  There are other ways to do this (which
probably would be better suited to standlone code snippets like this)

2) The guts of the implementation, creationComplete, looks to see if
the application has a top level tabStack component.  If it finds a
tabStack, it uses that instead of the application window.  You can
choose another component to align to, or you can strip out this code
entirely.


Now for the $1000 question, what effect does adding "deferred: true"
to the popups init vars really do?


P.S.  Someone else on this list provided the magic incantations for
showPopUpCentered.






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to