Creating Popup using ActionScript

To launch a pop-up, we use PopupManager class in flex. The example below demonstrates on how to create a popup using ActionScript. The PopUpManager singleton class creates new top-level windows and places or removes those windows from the layer on top of all other visible windows.

The PopUpManager also provides modality, so that windows below the popup cannot receive mouse events, and also provides an event if the user clicks the mouse outside the window so the developer can choose to dismiss the window or warn the user.

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”
layout=”horizontal”
verticalAlign=”middle”
backgroundColor=”white”
creationComplete=”init()”>

<mx:Panel id=”panel11″ width=”126″ height=”100″ layout=”absolute” title=”PopupManager”>
<mx:Button id=”but1″ x=”14″ y=”10″ label=”Click Here” click=”createPopUp(event)”/>
</mx:Panel>

<mx:Script>
<![CDATA[
import mx.containers.ControlBar;
import mx.containers.Panel;
import mx.controls.Button;
import mx.managers.PopUpManager;

private var panel:Panel;

private function init():void {

var cb:ControlBar = new ControlBar();

var b1:Button = new Button();
var b2:Button = new Button();

b1.label = "OK";
b1.addEventListener(MouseEvent.CLICK, closePopUp);
b2.label = "Cancel";
b2.addEventListener(MouseEvent.CLICK, closePopUp);

cb.addChild(b1);
cb.addChild(b2);

panel = new Panel();
panel.title = "RajiniKanth Panel";
panel.width = 240;
panel.height = 180;
panel.addChild(cb);
}

private function closePopUp(evt:MouseEvent):void {
PopUpManager.removePopUp(panel);
}

private function createPopUp(evt:MouseEvent):void {
PopUpManager.addPopUp(panel, this, true);
PopUpManager.centerPopUp(panel);
}
]]>
</mx:Script>
</mx:Application>

Popularity: 16% [?]

About the Author

Vinothbabu has written 24 stories on this site.

In short, my name is Vinoth babu { perra kettala summa authrithala } a UI expert from India, Chennai.

2 Comments on “Creating Popup using ActionScript”

  • John keppler wrote on 26 December, 2008, 6:30

    very nice article, thanks a lot

  • bharat wrote on 1 July, 2009, 17:57

    man code’s good but u must have been explained that.that’s not done .i have tones of codes but without explanation who knows what the heck going on huh?well u done a fantastic job .

Write a Comment

Gravatars are small images that can show your personality. You can get your gravatar for free today!

Copyright © 2010 HTTPguru. All rights reserved.

Our Partners:
WebHosting Jobs| UI expert | Packet Sniffer  | Mobile Home Refinancing  | Laptop LCD screens | CSS Creator| Exchange Hosting| Compare cable companies| Usa online casino | vps | Coupon Codes