Search Flex Samples

Creating custom pop-up windows with the PopUpManager class

The Alert control is great if you need to get a simple confirmation on an action which has a yes/no type answer, but what do you use when you need to prompt a user for their name or something else? JavaScript has a prompt(), and Flex has a very robust PopUpManager class.

This following example will demonstrate how to launch a custom Panel pop-up dialog which includes a Label control, TextInput control, and two Button controls. It also shows how to create a bunch of Flex components and containers using ActionScript instead of MXML.

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="" layout="vertical" verticalAlign="middle" backgroundColor="white" creationComplete="init()">



import mx.containers.ControlBar;

import mx.containers.Panel;

import mx.containers.VBox;

import mx.controls.Button;

import mx.controls.Label;

import mx.controls.Spacer;

import mx.controls.TextInput;

import mx.managers.PopUpManager;

private var panel:Panel;

private function init():void {

var vb:VBox = new VBox();

var label:Label = new Label();

var textInput:TextInput = new TextInput();

var cb:ControlBar = new ControlBar();

var s:Spacer = new Spacer();

var b1:Button = new Button();

var b2:Button = new Button();

s.percentWidth = 100;

b1.label = "OK";

b1.addEventListener(MouseEvent.CLICK, closePopUp);

b2.label = "Cancel";

b2.addEventListener(MouseEvent.CLICK, closePopUp);




label.text = "Please enter your name:";

vb.setStyle("paddingBottom", 5);

vb.setStyle("paddingLeft", 5);

vb.setStyle("paddingRight", 5);

vb.setStyle("paddingTop", 5);



panel = new Panel();

panel.title = "My Title";

panel.width = 240;

panel.height = 180;




private function closePopUp(evt:MouseEvent):void {



private function createPopUp(evt:MouseEvent):void {

PopUpManager.addPopUp(panel, this, true);





<mx:Button label="Launch Pop-Up" click="createPopUp(event)" />



Related Flex Samples

Learn Flex: Flex Samples | Flex Video Tutorials Flex Examples