package net.fdms.Frame
{
	import flash.display.DisplayObject;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.net.LocalConnection;
	import flash.system.System;
	/**
	 * ...
	 * @author Dawnboy
	 */
	public class StageSets 
	{
		private static var reSizeFuncs:Array = [];
		public function StageSets() 
		{
			
		}
		
		public static function init(stage:Stage):void {
			stage.scaleMode = "noScale";
			stage.align = "TL";
			stage.addEventListener(Event.RESIZE, onReSize);
		}
		
		/**
		 * 订阅场景大小改变通知
		 * @param	func
		 */
		public static function addResizeFunc(func:Function):void {
			if (!checkExist(func)) {
				reSizeFuncs.push(func);
			}
		}
		
		/**
		 * 订阅场景大小改变通知
		 * @param	func
		 */
		public static function delResizeFunc(func:Function):void {
			if (checkExist(func)) {
				reSizeFuncs.splice(reSizeFuncs.indexOf(func),1);
			}
		}
		
		/**
		 * 检查通知是否存在
		 * @param	func
		 * @return
		 */
		private static function checkExist(func:Function):Boolean {
			var n:int = reSizeFuncs.length;
			var result:Boolean;
			for (var a:int = 0; a < n; a++) {
				if (func == reSizeFuncs[a]) result = true;
				if (result) break;
			}
			return result;
		}
		/**
		 * 窗体大小改变后订阅库方法触发
		 * @param	e
		 */
		private static function onReSize(e:Event):void {
			var n:int = reSizeFuncs.length;
			for (var a:int = 0; a < n; a++) {
				reSizeFuncs[a]();
			}
			
		}
		
		public static function gc():void{
         try {
                (new LocalConnection).connect("foo");
                 (new LocalConnection).connect("foo");
           }catch(e:*){

                    trace(System.totalMemory);

                }

		}

		
	}

}