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 = Alert.show(“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 = Alert.show(“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!!!