当前位置:首页 > 开发 > 编程语言 > 编程 > 正文

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

发表于: 2012-11-14   作者:darrenzhu   来源:转载   浏览次数:
摘要: 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
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));
			}
		}
	}
}

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

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
Alert.show()里面有多个属性,其中排在第三是flags,这个属性作用 是在弹出的Alert提示框里面显示那
最近想实现一个可携带状态的线程池,具体需求就是池中的线程被用来处理某种信息,而此信息可视为线
任务 Executor框架使用Runnable作为任务的基本抽象。Runnable确实有限的抽象,虽然能够产生一些边界
最近在做flex ui做了一些,现在晒晒。希望跟大家都交流。 带序号和checkbox的grid: 带树的combobox
flex前台页面: <?xml version="1.0" encoding="utf-8"?> <ui:UIApplication xmlns:fx="ht
--------------201507160917更新--------------- 无意中发现标准消息框在Windows7是有声音的,只是
  在我的http://www.cnblogs.com/wuhenke/archive/2009/11/22/1608216.html 已经转载介绍了FlexRe
Doug又写了一个很cool的Flex 组件,可以带给用户很好的体验。这个组件扩展自Flex的ViewStack,使用了
使用Flex图表组件 以图表或是图的方式显示数据的能力可以使得Flex程序用户的数据交互更为容易。与仅
import mx.containers.Canvas; /** * 带网格的canvas * * @coder 衣旧 * * @date 2011-10-13 */ pub
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号