AlertBox With No Buttons! (HACK)
Posted by admin on January 10th, 2008 filed in AIR, Actonscript 3, FlexBrowsing around EE today, I found an interesting question. This person wanted an AlertBox that had no buttons at all. The goal was to have the identical functionality / look as an alert, but to only display a message such as “Saving Changes…”. This is something that I do all over the place, and have written custom components specifically for locking the UI until an operation is complete.
However, if you don’t mind using some nasty hacks, this functionality can be accomplished in only a couple lines of code.
private var theAlert:Alert;
public function showAlert():void
{
theAlert = Alert.show("Saving Changes...", "", Alert.OK);
theAlert.mx_internal::alertForm.removeChild(
theAlert.mx_internal::alertForm.mx_internal::buttons[0]);
}
public function hideAlert():void
{
PopUpManager.removePopUp(theAlert);
}
It’s a hack, but it works really good!
January 21st, 2008 at 7:27 pm
This works great, except one small thing, the user can still hit the ‘Enter’ key and the alert goes away, anything we can add to prevent that?
Thanks for the initial hack.
January 22nd, 2008 at 1:39 pm
Ah, never thought of that. Maybe try this:
private var theAlert:Alert;
public function showAlert():void
{
theAlert = Alert.show(”Saving Changes…”, “”, Alert.OK);
theAlert.mx_internal::alertForm.mx_internal::buttons[0].enabled = false;
theAlert.mx_internal::alertForm.removeChild(
theAlert.mx_internal::alertForm.mx_internal::buttons[0]);
}
public function hideAlert():void
{
PopUpManager.removePopUp(theAlert);
}
March 27th, 2008 at 5:28 am
Caracas… nem sabia desse mx_internal.. bom bom is good;; verry good.
Maybe try this:
theAlert.mx_internal::alertForm.mx_internal::buttons[0].setStyle(’color’, 0xffffff);
July 26th, 2008 at 12:42 pm
Hi,
great example. I love it. But I have one question: I created a timer to hide the AlertBox. But how can I update the text on the Alert? The trace shows me the output but the FlexApp is not showing any changes. Here is my code:
Maybe you can help me.
thanks Carsten