mx.managers.PopUpManager is a utility class in Flash MX 2004, Flash 8, Flex 1.5, and Flex 2 used to create popups. A popup is classified as a component that floats above the main application. Typically, Windows, Alerts, and ComboBox drop downs are used in this fashion. Developers utilize them for creating popup dialogues like preferences, login windows, etc.
Typically, the first parameter in Flash is set to _root. While not the best choice, as long as your SWF is never loaded, it’s a satisfactory choice. You are better off using your top level component, typically the one that wraps your entire application. Your main application class can provide a reference to itself for this purpose, or you can only delegate the “power of creating popups” to it, thus it can pass “this” in as the first parameter. Using _root, however, when using the centerPopUp method, it’ll utilize the whole movie to find out where the center is, thus nicely positioning the window in the center.
_level0 isn’t so hot because if your SWF is loaded into another one, you cannot prevent the popups from “invading” your main movie via _lockroot. This is the common fix for the ComboBox component in Flash when it’s used in a SWF that is loaded. The dropdown no longer works because the PopUpManager digs his way up to find the “one true _root”.
Seriously, I’m not justifying the use of _root, but if you’re in a rush and aren’t loading movies, it’s an acceptable choice.
Using the component that launched the PopUpManager isn’t so hot either because centering can get really jacked up if your component you are using is itself off-centered when using centerPopUp. Granted, there are valid use cases.
Using _root in Flex, however, isn’t such a good idea. Using it in Flash is bad enough; it’s a hardcoded reference to something. While the practice of loading Flex applications into other ones is frowned upon (by me at least), using archaic Flash references in a more Object Orienated codebase will confuse other Flex developers, and there is another way.
Using MovieClip(mx.core.Application) instead of _root is a more “wow my code doesn’t look hardcoded even though it is” way. You and I know what _root is, but some other Flex developers might not. Additionally, the casting to MovieClip is just so the compiler will leave you alone. Perfect example of where OOP gets in the way.
…2nd time in this blog entry I’ve been tempted to suggest using _root…
Do not use mx.core.Application.application, that’ll crash Flex. All that is is a static getter/setter that returns _level0, but for some reason it crashes your SWF.
In Flex 2, they actually provide a nice new method for us, popUpWindow. A conveinance method much like the Flex 1.5’s alert, which allowed you to easily create alerts with less code.
Again, popups are not just dialogues and forms-in-your-face, they can be for component GUI controls, as well. Just the other day, I created the popup slider that you have in Photoshop and Fireworks for adjusting alpha values; the actual slider is a popup. On the other end of the spectrum, entire mini-applications can be used as popups as well. They are draggable when using containers like Panel & TitleWindow if you don’t make them modal.