Alert component: non-modal pop-ups

Why, clever readers, did you know that you can use Flash MX Professional 2004’s Alert component to create non-modal pop-up windows instead of the default modal mode?

If you did, well, you can stop reading.

If you didn’t, you’re probably already typing up an angry email to me complaining how I haven’t defined the term “modal” or “nonmodal”. So, rest your ten angry digits and read on.

From our very own docs: A nonmodal window allows a user to interact with other windows in the application.

So, what this all means is that a modal Alert window prevents users from clicking on anything but the displayed Alert window itself. Therefore, a user can’t go any further until they dismiss the pop-up, similar to how the OS displays some error messages. A nonmodal Alert window lets users merrily click on either the Alert window or any components on gizmos underneath the Alert.

Enough of my jibber-jabber, on with some code…

Before you can test the code, add a copy of both the Button component and Alert component to your library. Add the follow code to Frame 1 of the main Timeline:

import mx.controls.Alert;

this.createClassObject(mx.controls.Button, “modal_button”, 10, {_x:10, _y:10});
this.createClassObject(mx.controls.Button, “nonmodal_button”, 20, {_x:120, _y:10});

modal_button.label = “modal”;
modal_button.addEventListener(“click”, modalListener); function modalListener(evt_obj:Object):Void {
var a:MovieClip =“This is a modal Alert window”, “Alert Test”, Alert.OK, this);
a.move(100, 100);

nonmodal_button.label = “nonmodal”;
nonmodal_button.addEventListener(“click”, nonmodalListener); function nonmodalListener(evt_obj:Object):Void {
var a:MovieClip =“This is a nonmodal Alert window”, “Alert Test”, Alert.OK | Alert.NONMODAL, this);
a.move(100, 100);

Test the movie, and click on the “modal” button to launch a modal window. This means you can no longer click on either of the Button instances on the Stage. Close the Alert and click the “nonmodal” button. Even though the nonmodal Alert window is visible, you can still click on either of the button instances on the Stage.

Thar ye be havin’ ‘t. Dasn’t say I neredo anythin’ fer ye. YAR!!!

4 Responses to Alert component: non-modal pop-ups

  1. Hello,I am a Canadian born engineer who is a Java programmer. Recently I have been thinking about buying Flash. It looks impressive. At this stage I guess I am wondering if these programs could be done in Flash: course you will need Java enabled to view them.Your answers, or lack thereof, should prove interesting. I guess I am particularly interested in Flash’s capabilities in parsing a non UML web site, something as pathetic and old fashioned as a CSV data site. The Java programs kind of have to do that, due to usage considerations. It looks like ActionScript is much like Java, so that is good. It also looks like Flash would be fun to play with, and Flash has version control down to an art…Thanks.Larry Druhall

  2. Michelle says:

    Does anybody know of a way to get the Alert component to react to the mouseDownOutside event, apart from having to use the PopUpManager class (shown below)?import mx.managers.PopUpManager;import mx.controls.Alert;var options:Object = {title:”Hello World”, text:”Danke”, okButton:true, cancelButton:true, defButton:Alert.CANCEL};var a:MovieClip = PopUpManager.createPopUp(this, Alert, true, options, true);a.addEventListener(“click”, miscHandler);a.addEventListener(“mouseDownOutside”, miscHandler);function miscHandler(eventObj:Object):Void {  trace(“Event: ” + eventObj.type);}

  3. Alvin says:

    hi larry,suffice to say that flash can certainly do those things.enjoy

  4. Ben Kress says:

    I was just wondering if anybody knew how to add the NumericStepper Component into the alert dialog box, or any custom button for that matter?