Tutorials Archive Save and Share your Tutorials

22Sep/090

Flex Alert! Listen to the buttons

The question of how to handle/listen to button clicks from the Alert control pops up (excuse the pun) quite often. To do this you need to create an actionscript function to handle the event. Other situations may arise where you also need to pass further information to the handler function. This post will show you how ;-)

The mx.controls.Alert class has a static method that shows the Alert control with the title, message, and requested buttons. The following code block will demonstrate how to declare a listener for your Alert control, as well as what to do when you catch the event.

In short, the code shows how to create an Alert control which has 2 buttons, Yes and No. Keep an eye out for for line 12 – this is where we delegate the button click listener to the handleAlert method.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import mx.controls.Alert;
import mx.utils.Delegate;
 
// show the Alert control
public function showAlert() : Void
{
    // the show method follows the method signature from the Flex Actionscript API
    Alert.show( "Are you sure?",
                         "Confirm Delete",
                         Alert.YES| Alert.NO,
                         null,
                         Delegate.create(this, this.handleAlert),
                         null,
                         Alert.YES);
}
 
// handle the Alert control button click
public function handleAlert( event:Object ) : Void
{
    if( event.detail == Alert.YES)
    {
        // YES button was clicked
    }
    else if( event.detail == Alert.NO)
    {
        // NO button was clicked
    }
}
VN:F [1.6.4_902]
Rating: 0.0/5 (0 votes cast)
VN:F [1.6.4_902]
Rating: 0 (from 0 votes)

   

Subscribe via Email

Follow me on Twitter

Categories

Archives

Calendar

March 2010
M T W T F S S
« Feb    
1234567
891011121314
15161718192021
22232425262728
293031  

Recent Posts

Recent Comments

Link Exchange

Meta

Stats

Web Directory

Internet photoshop tutorials, free photoshop tutorials, tutorials, tutorial search, tutorial links, find tutorials, photo shop tutorials, html tutorials,
blog directory Internet Blogs - BlogCatalog Blog Directory
TopOfBlogs