Flex loading

package util
{

	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.FocusEvent;
	import flash.events.MouseEvent;
	import flash.utils.clearInterval;
	import flash.utils.setInterval;

	import mx.containers.Canvas;
	import mx.containers.Panel;
	import mx.controls.Button;
	import mx.controls.Label;
	import mx.controls.SWFLoader;
	import mx.managers.PopUpManager;

	public class LoadingUI
	{

		private var canvas:Canvas;
		private var intervalId:uint;

		/**
		 * 打开等待画面
		 */
		public function createLoading(parent:DisplayObject):void
		{
			canvas=new Canvas();
			canvas.width=320;
			canvas.height=480;
			var lab:Label=new Label();
			lab.text="处理中,请耐心等待1秒...";
			lab.setStyle("fontSize", 14);
			canvas.addChild(lab);
			lab.x=85;
			lab.y=180;
			var loadingSwf:SWFLoader=new SWFLoader();
			loadingSwf.addEventListener(Event.COMPLETE, function(event:Event):void
				{
					loadingSwf.stage.frameRate=12;
				});
			loadingSwf.source="resources/loading.swf";
			loadingSwf.width=60;
			loadingSwf.height=60;
			canvas.addChild(loadingSwf);
			loadingSwf.x=130;
			loadingSwf.y=200;
			PopUpManager.addPopUp(canvas, parent, true);
			PopUpManager.centerPopUp(canvas);
			canvas.setFocus();
			canvas.addEventListener(FocusEvent.FOCUS_OUT, doFocusOut);
			intervalId=setInterval(doTimeOut, 1000, lab);
		}

		/**
		 * 关闭等待画面
		 */
		public function destroyLoading():void
		{
			if (canvas == null)
			{
				return ;
			}
			clearInterval(intervalId);
			canvas.removeEventListener(FocusEvent.FOCUS_OUT, doFocusOut);
			PopUpManager.removePopUp(canvas);
			canvas=null;
		}

		/**
		 * 等待时画面焦点始终在画板上
		 */
		private function doFocusOut(event:FocusEvent):void
		{
			event.preventDefault();
			canvas.setFocus();
		}

		/**
		 * 画面秒钟定时变化
		 */
		private function doTimeOut():void
		{
			var lab:Label=arguments[0]as Label;
			var tempStr:String=lab.text.substring(0, lab.text.length - 4);
			var i:Number=new Number(tempStr.substring(9, tempStr.length)) + 1;
			lab.text="处理中,请耐心等待" + i.toString() + "秒...";
		}
	}
}

你可能感兴趣的:(Flex,Flash)