Code I/O

A topnotch WordPress.com site


3 Comments

5 Minutes on Adobe Flex – Extending Alert …

Alert is pretty nice component, it got better when it was extended further.

It can be used as a confirmation, error or information dialog for instance to improve user experience.  This reuseable component will be good for you to do so.

AlertEx.as

package foss.afxtionlib.mx
{
	import mx.controls.Alert;
	public class AlertEx extends Alert
	{
		[Bindable]
		[Embed(source="assets/icons/48x48/info.png")]
		private static var InfoIcon:Class;
		[Bindable]
		[Embed(source="assets/icons/48x48/error.png")]
		private static var ErrorIcon:Class;
		[Bindable]
		[Embed(source="assets/icons/48x48/confirm.png")]
		private static var ConfirmIcon:Class;
		public function AlertEx()
		{
			super();
		}
		public static function info(message:String, closehandler:Function=null):void
		{
			show(message, "Information", Alert.OK, null, closehandler, InfoIcon);
		}
		public static function error(message:String, closehandler:Function=null):void
		{
			show(message, "Error", Alert.OK, null, closehandler, ErrorIcon);
		}
		public static function confirm(message:String, closehandler:Function=null):void
		{
			show(message, "Confirm", Alert.YES|Alert.NO, null, closehandler, ConfirmIcon);
		}
	}
}

The caller can then write the callback function to be called when the dialog is closed or handle the button click accordingly.

public static function alertClosed(event:Event):void
{
	trace("Alert Closed Handler: URL ==> " + redirectURL);
	var request:URLRequest = new URLRequest(redirectURL);
	navigateToURL(request, "_self");
}

AlertEx.info("Redirecting you to my home page!", alertClosed);

Quick Testing



public static function processFaultEvent(fe:FaultEvent):void
{
	AlertEx.confirm("Do you want to resubmit request?", handleAlert);
}

public static function handleAlert(event:Object):void
{
	if(event.detail == Alert.YES)
	{
		trace("'Yes' button clicked");
	}
	else if(event.detail == Alert.NO)
	{
		trace("'No' button clicked");
	}
}