Creating an application with the Alert component

The following procedure explains how to add an Alert component to an application while authoring. In this example, the Alert component appears when a stock hits a certain price.

To create an application with the Alert component:

  1. Select File > New and choose Flash File (ActionScript 2.0).
  2. Drag the Alert component from the Components panel to the current document's library.

    This adds the component to the library, but doesn't make it visible in the application.

  3. In the Actions panel, enter the following code in Frame 1 of the to define an event handler for the click event:
    import mx.controls.Alert;
    
    // Define action after alert confirmation.
    var myClickHandler:Function = function (evt_obj:Object) {
     if (evt_obj.detail == Alert.OK) {
      trace("start stock app");
     }
    };
    
    // Show alert dialog box.
    Alert.show("Launch Stock Application?", "Stock Price Alert", Alert.OK | Alert.CANCEL, this, myClickHandler, "stockIcon", Alert.OK);
    

    This code creates an Alert window with OK and Cancel buttons. When the user clicks either button, Flash calls the myClickHandler function. The myClickHandler function instructs Flash to trace "start stock app" when you click the OK button.

    NOTE

    The Alert.show() method includes an optional parameter that displays an icon in the Alert window (in this example, an icon with the linkage identifier "stockIcon"). To include this icon in your test example, create a symbol named stockIcon and set it to Export for ActionScript in the Linkage Properties dialog box or the Create New Symbol dialog box. The graphics for the stockIcon symbol should be aligned to coordinates (0,0) in the symbol's coordinate system.

  4. Select Control > Test Movie.