As i just wanted to insert some bold text into an Alert box, I wondered why the Flex Alert doesn’t support HTML Text. So i wrote a Custom Alert class which just overwrites the regular Alert.show(). Through a trick, it allows to use HTML tags inside the text.
package tools
{
import flash.display.Sprite;
import mx.controls.Alert;
import mx.core.IFlexModuleFactory;
import mx.core.mx_internal;
/**
* Alert-Box which makes using HTML text possible
*/
public class HTMLAlert extends Alert
{
/**
* Given text is interpreted as HTML text,
* Example: "bold text" is rendered as bold text.
*/
public static function show(text:String = "", title:String = "",
flags:uint = 0x4,
parent:Sprite = null,
closeHandler:Function = null,
iconClass:Class = null,
defaultButtonFlag:uint = 0x4,
moduleFactory:IFlexModuleFactory = null):Alert
{
var alert:Alert = Alert.show(text, title, flags, parent,
closeHandler, iconClass, defaultButtonFlag, moduleFactory);
alert.mx_internal::alertForm.mx_internal::textField.htmlText = text;
return alert;
}
}
}
Just use it by calling it like the regular Alert-class:
HTMLAlert.show("A bold Alert text", "HTMLAlert", Alert.OK);

4 Comments
Hey,
happy new year,
how comes that u have to use Flex?
I hope we will see us soon,
karfau
Thx for ur comment
Happy new year to you, too!
I’m currently helping a student getting a little Flex-project running – in my spare time.
Yeah i think we’ll meet again after AS finished his thesis.
Many thanks for this class. Very usefull!
Brilliant… Thanks for sharing. I was trying to do the same.