« ScrapBlog
» Adding a mask to graphic components

ActionScript, Flex 2, MXML

Simple modal window in ActionScript

Stelian Crisan | 29.10.07 | 2 Comments

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);

Popularity: 38%

Share and Enjoy:
  • Technorati
  • StumbleUpon
  • del.icio.us
  • NewsVine
  • Reddit
  • Digg
  • Furl
  • co.mments
  • blogmarks
  • Slashdot
  • DZone
  • Taggly
  • YahooMyWeb
  • connotea
  • Webride




Tags: , ,

This post was written by Stelian Crisan

Views: 3486

related

popular

2 Comments

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

:

:


« ScrapBlog
» Adding a mask to graphic components