自定义载入类(如图片、XML)

package leon.utils{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.display.DisplayObjectContainer;
	import flash.net.URLRequest;
	import flash.net.URLLoader;
	import flash.events.EventDispatcher;
	import leon.events.LoadEvent;

	public class LoadManager extends EventDispatcher {
		private var _loader:Loader;
		private var _container:DisplayObjectContainer;

		public static const LOADED:String="loaded";

		public function LoadManager(_container:DisplayObjectContainer):void {
			this._container=_container;
			//trace("ddd");
		}

		public function LoadImage(_url:String):void {
			if (! _loader) {
				_loader=new Loader();
			}
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,_loaded,false,0,true);
			_loader.load(new URLRequest(_url));
		}

		private function _loaded(e:Event):void {
			//dispatchEvent(new Event(LOADED));
			dispatchEvent(new LoadEvent(LOADED,"低调点"));
			this._container.addChild(_loader);
		}

		public function get x():Number {
			return this._container.x;
		}

		public function set x(value:Number):void {
			this._container.x=value;
		}

		public function get y():Number {
			return this._container.y;
		}

		public function set y(value:Number):void {
			this._container.y=value;
		}

		public function unload():void {
			var _num:int=this._container.numChildren;
			if (_loader) {
				if (_num>0) {
					_loader.unloadAndStop();
				}
			}
		}
	}
}
posted @ 2010-06-21 22:07  LT世纪  阅读(210)  评论(0编辑  收藏  举报