package classes.matuto.display
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	
	public class BasicSprite extends Sprite
	{
		
		protected var stageWidth 	:Number = NaN;
		protected var stageHeight	:Number = NaN;
		public   var rootStage		:Stage;
		
		public function BasicSprite()
		{
			addEventListener(Event.ADDED_TO_STAGE, added_handle, false, 0, true);
			addEventListener(Event.REMOVED_FROM_STAGE, removed_handle, false, 0, true);
		}
		
		private function added_handle(e :Event) :void
		{
			rootStage   = stage;
			stageWidth 	= stage.stageWidth;
			stageHeight	= stage.stageHeight;
			
			stage.addEventListener(Event.RESIZE, resize_handle, false, 0,true);
			
			try{
				this["added"]();
			}catch(e :Error){
				
			}
			
			resize_handle(null);
		}
		
		private function removed_handle(e :Event) :void
		{	
			if(rootStage) rootStage.removeEventListener(Event.RESIZE, resize_handle);
			try{
				this["removed"]();
			}catch(e :Error){
				
			}
		}
		
		private function resize_handle(e :Event) :void
		{
			if(stage)
			{
				stageWidth 	= stage.stageWidth;
				stageHeight	= stage.stageHeight;
				
				try{
					this["onResize"]();
				}catch(e :Error){
					
				}
			}else
			{
				if(rootStage) rootStage.removeEventListener(Event.RESIZE, resize_handle);
			}
		}
		
		public function get enabled() :Boolean
		{
			return mouseEnabled;
		}
		
		public function set enabled(value :Boolean) :void
		{
			mouseEnabled = mouseChildren = value;
		}
		
	}
}