Simple Flex hacking: Alert control

I hate using the Alert control in Flex, but sometimes you just need a quickie prompt, and for the most part, it does what you need it to do, has some easy to edit skinning possibilities, etc.

I ran into a random annoyance though – I wanted to edit the text of an Alert control, after it was made, without removing it and recreating it. In my case, simply showing the counting down of a timer in an Alert’s text.

As mentioned in the docs, the show() method of Alert is static. But in looking through the Alert and AlertForm classes (mx\controls\Alert.as and mx\controls\alertClasses\AlertForm.as) you’ll find that some variables have the mx_internal namespace.

Sure enough, you can in fact access properties with this namespace (see code) and open quite a bit of editing that Adobe probably wouldn’t necessarily want to have available.

var timeoutPrompt:Alert;
timeoutPrompt = Alert.show("Added...");
timeoutPrompt.mx_internal::alertForm.mx_internal::textField.text = "Edited...";
timeoutPrompt.mx_internal::alertForm.mx_internal::textField.selectable = false;