Saturday, November 12, 2011
Custom Alert Component
// Use this custom Alert Component
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
width="{_width}" height="{_height}"
title="{_title}"
showCloseButton="true"
close="alertClose()">
<mx:Script>
<![CDATA[
import mx.core.Application;
import mx.controls.Alert;
//import mx.events.CloseEvent;
import mx.managers.PopUpManager;
[Bindable] private static var _title:String = "";
[Bindable] private static var _text:String = "Alert text";
[Bindable] private static var _width:Number = 400;
[Bindable] private static var _height:Number = 400;
private function alertClose():void{
PopUpManager.removePopUp(this);
}
public static function showAlert(alertText:String,alertTitle:String="",displayObject:DisplayObject=null):void{
if (alertText != null && alertText != ""){
_text = alertText
}
if (alertTitle != null && alertTitle != ""){
_title = alertTitle;
}
if (displayObject == null){
//derived from source code of Alert.show, line 476
displayObject = DisplayObject(Application.application);
}
_height = displayObject.height - 100;
_width = displayObject.width - 100;
var alert:CustomAlert = PopUpManager.createPopUp(displayObject,CustomAlert,true) as CustomAlert;
PopUpManager.centerPopUp(alert);
}
]]>
</mx:Script>
<mx:VBox width="100%" height="100%" horizontalAlign="center">
<mx:TextArea text="{_text}" width="100%" height="100%"/>
<mx:Button label="OK" click="alertClose()" horizontalCenter="0"/>
</mx:VBox>
</mx:TitleWindow>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment