Using PopUpManager.addPopUp from ActionScript classes

A fairly typical use case I frequently run into is the need to display some form of TitleWindow using the PopUpManager class (usually when a simple Alert won’t do the job).  This is simple when addPopUp is invoked from within a view (MXML):

 PopUpManager.addPopUp(titleWindow, this);
 

The keyword this is fine when calling from within an view as it refers to the current DisplayObject.  When calling from a pure ActionScript class however this won’t work as “this” refers to the class and not a Display Object.

Instead, to get a reference to the root application (which is normally good enough if you just want to display a simple popup) use the following:

 PopUpManager.addPopUp(titleWindow, Application.application.getChildAt(0));
 

This will add the popup to the root display object contained within the Application.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s