Oct 13, 2007

Flash Alert Message

The Alert component lets you display a window that presents the user with a message and response buttons. The window has a title bar that you can fill with text, a message that you can customize, and buttons whose labels you can change. An Alert window can have any combination of Yes, No, OK, and Cancel buttons, and you can change the button labels by using the Alert.okLabel, Alert.yesLabel, Alert.noLabel, and Alert.cancelLabel properties. You cannot change the order of the buttons in an Alert window; the button order is always OK, Yes, No, Cancel. An Alert window closes when a user clicks any of its buttons.



You can use an Alert component whenever you want to announce something to a user. For example, you could display an alert when a user quit the player without saving informations properly .Here I explain ,how to handle Alert componet

Step 1:

Open the Component Panel ( Windows-> Components / ctrl + F7) .There you can Find Alert Component under user interface catagery .You will get the panel like below image

Step 2:

Double-click the Alert component in the Components panel to add it to the Stage.

Step 3:

Press Backspace (Windows) or Delete (Macintosh) to delete the component from the Stage.
This adds the component to the library, but doesn’t make it visible in the application.Your Library panel looks like

Note :Before start the coding , you have to verify whether Alert Componet added in the Library file. If its not added in library file means your code doesn't help you.

Step 4 :

Make one button instance on Stage, And set the instance name as "btn".

Step 5 :

// To add alert component

import mx.controls.Alert;

//Showing alert Mesage on button click Event

btn.onPress=function()

{

Alert.show("Want to see Alert Message Now?", "Alert", Alert.OK | Alert.CANCEL, this, myClickHandler, "stockIcon", Alert.OK);

}

To simply give the warn message means ,up to this enough. If you proceed further according to the response (ie, OK/CANCEL) means, You have to set the Event handler.for the click event:

myClickHandler = function (evt)

{

if (evt.detail == Alert.OK)

{

op_txt.text="You select the OK Option"; // startStockApplication();

}

if (evt.detail == Alert.CANCEL)

{ op_txt.text="You select the CANCEL Option";

}

}

That's it.You done it. Give ctrl+Enter to Run the Movie

DownLoad Source Code

No comments: