Search Flex Components Free

Custom Search

December 19, 2007

Changing the default button labels on an Alert control

When I first started playing with the Alert control, this tripped me up for a couple minutes. When trying to override the default text on the Alert control’s buttons, you need to set the Alert.cancelLabel, Alert.noLabel, Alert.okLabel, and/or Alert.yesLabel static properties *before* calling the Alert.show(). Sure, sounds a bit obvious in hindsight, but it is also important to remember that since those values are static, they apply to all Alerts, not just the one specific Alert. So you may have to reset the values back to their defaults once the Alert has been displayed.
Full code after the jump.
The following example displays an Alert dialog and overrides the default values for the Alert.noLabel and Alert.yesLabel properties:

<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" creationComplete="showAlert()">
<mx:Script> <![CDATA[ import mx.controls.Alert;
private var a:Alert;
private function showAlert():void { Alert.noLabel = "Non"; Alert.yesLabel = "Oui";
Alert.show("message goes here", "title goes here", Alert.NO Alert.YES); } ]]> </mx:Script>
<mx:Button label="Alert.show()" click="showAlert();" />
</mx:Application>

Related Flex Tutorials