Archived:How to implement alert screens using exceptions in ActionScript 2.0

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

We do not recommend Flash Lite development on current Nokia devices, and all Flash Lite articles on this wiki have been archived. Flash Lite has been removed from all Nokia Asha and recent Series 40 devices and has limited support on Symbian. Specific information for Nokia Belle is available in Flash Lite on Nokia Browser for Symbian. Specific information for OLD Series 40 and Symbian devices is available in the Flash Lite Developers Library.

Article Metadata
Code ExampleCompatibility
Created: cristovaodoj (29 Mar 2010)
Last edited: hamishwillee (14 May 2013)



When we are designing an application, we always need alert screens to get the user attention or show an error that occurred. Most cases we code these alerts and its actions in the main application, which causes an ugly and a hard understanding code in the final result. To solve this problem I propose creating a class that extends from Error object (represents the exception object in ActionScript 2.0) with the MovieClips and Buttons objects inside this class; at last to use it you only need throw an exception in your main application.

Step 1: Creating your alert screen.

The aim of this step is creating your own visual alert screen. Here I'm going to show you how to make a basic one, but it can be easily modified to increase functionalities.

1.1 - First you need to create a MovieClip with a 50% transparency with name alert_screen_mc;

Note.pngNote: Remember to export the alert_screen_mc MovieClip for the ActionScript.

1.2 - Put a 100% transparent button to block the mouse events;

1.3 - Create another MovieClip with name alert_box_mc with the following objects inside:

  • A text field with instance name text_field;
  • A button with name ok_btn.

Your alert should looks like with the shown below:


Step 2: Creating your own exception class

It's easy creating and extending an Error class. You only need use the word [extends] as shown below:

class MyOwnException extends Error {
private var message:String; //message to show on the alert box.
public function MyOwnException(message:String, alert_type:String) {
this.message = message;
// Create and attach the alert to your stage.
var target = _root.attachMovie(alert_type, "current_shown_alert", 1000, 0, 0);
// Insert the message in the text field at the alert box.
target.alert_box_mc.text_field.text = message;
// Remove the alert from your stage when clicking the button.
target.alert_box_mc.ok_btn.onRelease = function() {

Your constructor receives two parameters: the message that you want to be shown and your alert screen name (created in the step 1).

Step 3: Using your exception

This is the easier step of all; only need throw your recently created exception and then you'll can see your alert on the screen. When you click the ok button the alert will disappear.

Example throwing an exception to show the alert screen:

throw new MyOwnException("My exception message.", "alert_screen_mc");

Note.pngNote: Just start the application and the alert will be shown.

Source Code for Download


This page was last modified on 14 May 2013, at 02:39.
46 page views in the last 30 days.