Flex Mobile Development: Creating Dialog Windows

Ever wondered how to create a modal dialog window in Flex mobile applications? For example, you may want to ask the user for a confirmation when he performs a delete operation or maybe to select an item from a list. Well, if you don’t know how to do it, then read on.

Flex has a class that just does this: SkinnablePopUpContainer. SkinnablePopUpContainer extends SkinnableContainer class and has a very simple API you can use in order to “open” and “close” the dialog.

Understanding SkinnablePopUpContainer

Because SkinnablePopUpContainer extends the SkinnableContainer it is extremely easy to create any kind of dialog window you want. You can create a new MXML component that extends the SkinnablePopUpContainer. Then you set a layout manager that works for you (VerticalLayout, HorizontalLayout). And finally, you add the UI components you need – labels, buttons, lists, and so on.

Suppose you want to create a simple alert window that looks like this:

Here is the code to implement this (as a new MXML component that extends SkinnablePopUpContainer):

<?xml version="1.0" encoding="utf-8"?>
<s:SkinnablePopUpContainer xmlns:fx="http://ns.adobe.com/mxml/2009"

        <s:VerticalLayout horizontalAlign="center"/>

   <s:Label text="The contact was saved" width="100%" textAlign="center"/>
   <s:Button label="OK" width="100%" click="this.close()"/>

The API for controlling the SkinnablePopUpContainer is pretty simple:

  • To open or display the window you create a new instance and then call the open() method of SkinnablePopUpContainer. This method has two arguments. The first argument is the display object container where it will be created. The second argument is a flag that tells Flex if the window will be modal or not.
  • To close the window and send data from the window to the application you use the close() method of SkinnablePopUpContainer. This methods also has two arguments. The first argument is a flag. You can set this to true if, for example, the user clicked the OK button, and false otherwise. If you want to send some data back to the application you use the second argument. For example, if you have a TextInput in your dialog and you want to send the text you will use this second argument.
  • To listen for the close event and read the data sent from the SkinnablePopUpContainer you have to register an event listener on the SkinnablePopUpContainer. The event type is PopUpEvent. PopUpEvent has two properties that you can use to read the flag and data set when calling the close() method: commit and data.

Here is an example of how to open a SkinnablePopUpContainer component and read the flag/data when it is closed:

//create the component and open it
var alertWindow:SkinnablePopUpContainer = new SkinnablePopUpContainer();
alertWindow.addEventListener(PopUpEvent.CLOSE, onAlertClose, false, 0, true);
alertWindow.width = stage.width;
alertWindow.height = stage.height / 2;
alertWindow.x = 0;
alertWindow.y = 100;
alertWindow.open(this, true);

private function onAlertClose(event:PopUpEvent):void {
    alertWindow = null;

Creating custom dialog windows

Once you understand how to use the SkinnablePopUpContainer it is pretty simple to create any kind of dialog window you might need: confirmation messages, simple alerts, pop up lists, and so on. Here is the code for a confirmation window that has two buttons (Yes and No) and lets you set the message text:

[snippet id=57728]

And here is how this component look on my Android phone:

And here is the code for a pop up list that lets you to set the title, the list’s data provider, the list’s label field, the list’s initial selected items, and multiple selections (you can retrieve the selected items by listening for PopupEvent.CLOSE and reading the data attribute).

[snippet id=57729]

And here is the component running on my phone:


The two custom dialog windows I showed you in the previous section use the default look and feel. What about skinning a SkinnablePopUpContainer? There is a Flex class that provides the default skin for a SkinnablePopUpContainer: SkinnablePopUpContainerSkin. By creating a skin that extends this default skin you can change the background of the component quite easily. If you look at the SkinnablePopUpContainerSkin skin you’ll notice that it has a rect with the id equal to background. This is the starting point to change the default background. You can draw additional stuff on top of this background or replace it alltogether with an FXG or PNG file.

For the rest of the UI components used in a SkinnablePopUpContainer (buttons, text inputs, labels, and so on) you will create additional skins and/or use CSS. Here is a screenshot with the same confirmation window but this time using a custom skin:

Here is the skin class used to customize the confirmation window presented in the previous section:

[snippet id=57730]

And this is the FXG used by the skin class to draw the background:

[snippet id=57731]


You can download a working Flex project that includes all the code used in this article from here.

9 thoughts on “Flex Mobile Development: Creating Dialog Windows

  1. hi, i am reading your blog while i am preparing to show how to create a preference view in native android and mobile flex. :) thanks for the post

  2. Hi this Popup list works like a charm thank you, But I have noticed an error when you try to populate the array with only one record. Can you try it out and let me know

  3. Why is SkinnablePopUpContainerSkin extending the mxml skin classes ? They say mxml skin with state are a performance killer for mobile…

    This popup is a bit sluggish on iPad1, I was forced to recreate the skin base on MobileSkin.

  4. Hi Mihai,

    Thanks for this good alert window example on a Flex Mobile.

    I started to use it and would say that the implementation was quite straightforward.

    I do have a question though. In my 7″ Galaxy Tab, the alert displays the width properly, but for some reason, the same does not display on a Galaxy Note phone.

    Any area which you think I should look at?



  5. I’d like to see a full on custom popup. For example why do you give the popup container a layout, shouldn’t that be handled by the skin class.
    I’m trying to create a popup with the popup container containing only the components and some logic, then trying to use the skin to deal with layout (as well as excluding various skin parts). Can’t seem to do it in just mxml. Would be nice to see an example of this.

  6. I am building an app for tablets(ipad,playbook) and wld like to know if this can be used to achieve a modal box dat plays a video on popup, as in putting a mediacontainer element from OSMF into the modal popup so when a user finish viewing the video, they can close the popup and launch anoda video.

Leave a Reply