`
darrenzhu
  • 浏览: 782472 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Flex可携带数据的Aler组件(DataCarriableAlert)

阅读更多
package component.alert
{
	import flash.display.Sprite;
	import flash.events.EventPhase;
	import mx.controls.Alert;
	import mx.core.FlexGlobals;
	import mx.core.IFlexDisplayObject;
	import mx.core.IFlexModule;
	import mx.core.IFlexModuleFactory;
	import mx.core.UIComponent;
	import mx.events.CloseEvent;
	import mx.events.FlexEvent;
	import mx.managers.ISystemManager;
	import mx.managers.PopUpManager;
	
	/**
	 * Alert control provided by flex sdk is not supportted to carry data in close handler, only a predefined closeEvent object,</br>
	 * you can use DataCarriableAlert to resolve this problem, you can obtain both the closeEvent object and your parameters.
	 * Usage example:</br>
	 * 	DataCarriableAlert.show("Are you sure to delete the selected trades?","Message",Alert.YES|Alert.NO,this,deletionConfirm,[2]);</br>
	 *	
	 * </br>private function deletionConfirm(e:CloseEvent,intv:int):void{</br>
	 * &nbsp;&nbsp;//intv is 2 which was passed by above code</br>
	 *	&nbsp;&nbsp;if(e.detail==Alert.NO){</br>
	 *	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;</br>
	 *	&nbsp;&nbsp;&nbsp;}</br>
	 *	}</br>
	 */ 
	public class DataCarriableAlert extends Alert
	{
		public function DataCarriableAlert()
		{
			super();
		}

		public static function show(text:String = "", title:String = "",
									flags:uint = 0x4 /* Alert.OK */, 
									parent:Sprite = null, 
									closeHandler:Function = null, 
									closeHandlerParameters:Array=null,
									iconClass:Class = null, 
									defaultButtonFlag:uint = 0x4 /* Alert.OK */,
									moduleFactory:IFlexModuleFactory = null):Alert
		{
			var modal:Boolean = (flags & Alert.NONMODAL) ? false : true;
			
			if (!parent)
			{
				var sm:ISystemManager = ISystemManager(FlexGlobals.topLevelApplication.systemManager);
				// no types so no dependencies
				var mp:Object = sm.getImplementation("mx.managers.IMarshallPlanSystemManager");
				if (mp && mp.useSWFBridge())
					parent = Sprite(sm.getSandboxRoot());
				else
					parent = Sprite(FlexGlobals.topLevelApplication);
			}
			
			var alert:Alert = new Alert();
			
			if (flags & Alert.OK||
				flags & Alert.CANCEL ||
				flags & Alert.YES ||
				flags & Alert.NO)
			{
				alert.buttonFlags = flags;
			}
			
			if (defaultButtonFlag == Alert.OK ||
				defaultButtonFlag == Alert.CANCEL ||
				defaultButtonFlag == Alert.YES ||
				defaultButtonFlag == Alert.NO)
			{
				alert.defaultButtonFlag = defaultButtonFlag;
			}
			
			alert.text = text;
			alert.title = title;
			alert.iconClass = iconClass;
			
			/********************************override part start****************************************************************/
			if (closeHandler != null){
				alert.addEventListener(CloseEvent.CLOSE, 
					function(closeEvent:CloseEvent):void{
						var parameters:Array=[];
						parameters.push(closeEvent);
						if(closeHandlerParameters!=null && closeHandlerParameters.length>0){
							for each(var p:Object in closeHandlerParameters){
								parameters.push(p);
							}
						}
						closeHandler.apply(alert,parameters);
					}
				)
			}
			/********************************override part end*******************************************************************/
				
			
			// Setting a module factory allows the correct embedded font to be found.
			if (moduleFactory)
				alert.moduleFactory = moduleFactory;    
			else if (parent is IFlexModule)
				alert.moduleFactory = IFlexModule(parent).moduleFactory;
			else
			{
				if (parent is IFlexModuleFactory)
					alert.moduleFactory = IFlexModuleFactory(parent);
				else                
					alert.moduleFactory = FlexGlobals.topLevelApplication.moduleFactory;
				
				// also set document if parent isn't a UIComponent
				if (!parent is UIComponent)
					alert.document = FlexGlobals.topLevelApplication.document;
			}
			
			alert.addEventListener(FlexEvent.CREATION_COMPLETE, static_creationCompleteHandler);
			PopUpManager.addPopUp(alert, parent, modal);
			
			return alert;
		}
		
		private static function static_creationCompleteHandler(event:FlexEvent):void
		{
			if (event.target is IFlexDisplayObject && event.eventPhase == EventPhase.AT_TARGET)
			{
				var alert:Alert = Alert(event.target);
				alert.removeEventListener(FlexEvent.CREATION_COMPLETE, static_creationCompleteHandler);
				
				alert.setActualSize(alert.getExplicitOrMeasuredWidth(),
					alert.getExplicitOrMeasuredHeight());
				PopUpManager.centerPopUp(IFlexDisplayObject(alert));
			}
		}
	}
}
分享到:
评论

相关推荐

    TMC Aler C 标准

    本资源提供关于汽车交通事故事件的解决方案和标组。对于了解TMC 有很大帮组。TMC在汽车Navigationg系统中有很大的应用,在未来有很大的应用前景和商业价值。

    resize数据文件大小

    缩减数据文件大小,用于系统存储空间紧张的情况下,保证数据库正常运行 (分享以下内容旨在传递信息之用途 , 请在使用后及时完成评估并在24小时内删除 , 否则一切后果请您自负)

    Aler_Covid19

    Aler_Covid19

    wicket-js:wicket-js 使在 Wicket 组件和行为中编写和处理自定义 JavaScript 和 jQuery 变得容易

    Wicket JavaScript 和 jQuery wicket-js 使在组件和行为中编写和处理自定义 JavaScript 和变得容易。 它有助于将 Wicket Ajax Behavior 侦听器与实际客户端 UI 功能分开,同时保持与 ... return new JsCall ( " aler

    js提示框替代系统alert,自动关闭alert对话框的实现方法

    自己写了个alert提示框。因为系统alert在苹果手机微信中,提示时,顶部会显示网站地址。 同时其他后续操作需要在js中继续填写。因此简单用div写了一个alert提示框,并自动关闭。 效果图 css样式 ...

    RACAlertAction:支持 ReactiveCocoa 的 UIAlertAction 子类

    RACAlertAction 支持 ReactiveCocoa 的 UIAlertAction 子类。 目的 iOS 8 引入了UIAlertController ,一个上面的抽象和UIAlertView替代品。 UIAlertController使用UIAlertAction实例来表示按钮(以及这些按钮的动作...

    moss中Service Unavailable的解决方法

    moss中Service Unavailable的解决方法,文件中列出了几种解决方式

    Fragment后退栈和add,remove,replace的基本使用

    Fragment后退栈和add,remove,replace的基本使用.

    sd-alert-pipe:Star Destroyer库,用于与各种经纪人进行交互

    当前支持的经纪人:上面的每个模块都定义了一个服务,该服务包含各种用于从各个API提取数据的方法,通常用于特定的ZTF名称。安装在全新的virtualenv中, pip install -r requirements.txt用法在脚本中,从导入...

    RTSPAllTheThings:不推荐使用的RTSP媒体服务器-使用github.comaler9rtsp-simple-server代替

    RTSPAllTheThings:不推荐使用的RTSP媒体服务器-使用github.comaler9rtsp-simple-server代替

    jQuery实现html双向绑定功能示例

    本文实例讲述了jQuery实现html双向绑定功能。分享给大家供大家参考,具体如下: &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;... aler

    Bootstrap 警告(Alerts)

    Bootstrap 警告(Alerts) 本章将讲解警告(Alerts)以及 Bootstrap 所提供的用于警告的 class。警告(Alerts)向用户...,并向其添加一个 .alert class 和四个上下文 class(即 .alert-success、.alert-info、.aler

    JSPsession超时提示

    用戶登錄了,現在已經存在不管到任何頁面只要不做操作,到了10分鐘aler(session超時),重新登錄的。

    Bootstrap警告框(Alert)插件使用方法

    1、通过 data 属性:通过数据 API(Data API)添加可取消功能,只需要向关闭按钮添加 data-dismiss=”alert”,就会自动为警告框添加关闭功能。 ×  2、通过 JavaScript添加可取消功能: $(“.aler

    功能齐全的alert视图

    源码HLAlertController,一个非常简洁 但功能齐全的alert 用于替换系统的aler 主要是因为(ios 7 和ios 8的不同 需要调用不同的aler) 非常容易使用 [lang=objc] HLAlertController *alert = [HLAlertController ...

    gortsplib:用于Go编程语言的RTSP 1.0客户端和服务器库

    gortsplib 用于Go编程语言的RTSP 1.0客户端和服务器库,是为编写的。 Go≥1.14是必需的。 特征: 客户 从具有UDP或TCP的服务器读取流 使用UDP或TCP将流发布到服务器 使用TLS(RTSPS)加密流 查询服务器有关已发布流...

    ExtJs的Ext.Ajax.request实现waitMsg等待提示效果

    一、 fp.form.submit 有waitMsg 属性来设置等待效果,如下。但是对于Ext.Ajax.request来说 waitMsg 并不起... waitMsg : '正在提交数据,请稍后... ...', success : function(form, action) { Ext.MessageBox.aler

    chat-app-v2:简短的聊天应用演示

    第App v2版 1.安装CLI并创建应用 $ npm install -g ember-cli $ ember new chat-app $ cd chat-app $ ember server 灰烬督察 $ ember g模板应用程序 2.添加引导程序和一些CSS 搜索引导程序包: : ....aler

    android监听返回按钮事件的方法

    本文实例讲述了android监听返回按钮事件的方法。分享给大家供大家参考。具体如下: 用户在点击手机的返回按钮时,默认是推出当前的activty,但是有时用户不小心按到返回,所以需要给用户一个提示,这就需要重写... Aler

    jquery如何改变html标签的样式(两种实现方法)

    对于如何修饰html标签,这对于js来说,可以通过setAttribute来设置标签的属性,通过getAttribute来得到标签的属性,而在jq中当然也可以实现类似的功能,方法上肯定比js要简化多了。 一 通过修改标签属性来...”) aler

Global site tag (gtag.js) - Google Analytics