O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

11.15. Alerting Users to Validation Errors

Problem

You want to alert the user when there is a validation error in the form data.

Solution

Use a message box.

Discussion

The MessageBox component is the perfect way to alert users when there is a form validation error. The MessageBox component can be found in Flash UI Components Set 2, which is available for free from the Macromedia Flash Exchange (http://www.macromedia.com/exchange/flash). You can add a message box programmatically using attachMovie( ), as you can with any other component. You only need to make sure that the component symbol is included in the Flash document’s Library, as described in Recipe 11.1. The linkage identifier for the symbol is FMessageBoxSymbol.

this.attachMovie("FMessageBoxSymbol", "myMessageBox", 1);

Normally, you don’t want a message box to be visible when the movie starts. Instead, you want to make the message box visible only if and when there is something about which to alert the user. Therefore, you should initialize a message box by setting its _visible property to false. You can do this either after attaching the movie clip or during the attachMovie( ) invocation by using an initialization object, as follows:

this.attachMovie("FMessageBoxSymbol", "myMessageBox", 1, {_visible: false});

Additionally, when you attach a message box programmatically, you must specify the buttons to include in the message box using the setButtons( ) method. The method expects an array of labels for the buttons. Typically, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required