So you need a modal window and you are using Flex
. This a small example that will open a modal window when application it’s initialized. I put the title to the modal window, but you can add also an icon.
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="openModalWindow()"> <mx:Script> <![CDATA[ import mx.containers.Canvas; import mx.managers.PopUpManager; import mx.containers.TitleWindow; import mx.controls.Label; public function openModalWindow():void { //define title window var _titleWindow:TitleWindow = new TitleWindow(); _titleWindow.title = "New modal window"; //define and add canvas var _tmpCanvas:Canvas = new Canvas(); _tmpCanvas.height = 100; _tmpCanvas.width = 300; _titleWindow.addChild(_tmpCanvas); //define and add label var _tmpLabel:Label = new Label(); _tmpLabel.text = "Your modal window content."; _tmpCanvas.addChild(_tmpLabel); //add modal window PopUpManager.addPopUp(_titleWindow, this,true); //center modal window PopUpManager.centerPopUp(_titleWindow); } ]]> </mx:Script> </mx:Application>
The parent display object of new pop-up window is set to this, in this case it’s the main application. To set up this new pop-up as modal window you just have to set modal parameter as true as it’s in this example:
PopUpManager.addPopUp(_titleWindow, this,true);
Tags: flex. actionscript, modal window, MXML
This post was written by Stelian Crisan
Views: 11198










Hi:
I like this compact nature of this code. However, it seems to have some flaws in it. For instance, there is a dangling “;” at the end of the first line, and the start of the script area is commented out.
I copied the code, fixed those errors, and tried to run it, and could not make it go. Could you refresh it?
Thanks!
Hi Andrew,
You have right, the code was not clear, I just update and test the code. Thank you for your observation.
Hey ! thx for the simple example.