티스토리 뷰

728x90
반응형
여러개의 썸네일들을 마우스오버시 다른 썸네일보다 최상위에 배치하여 썸네일을 보여줘야 하고
또 마우스 아웃시엔 다시 원래대로의 뎁스를 유지시켜야 하는 머 그럴때가 종종 있다~
그래서 그것을 위해 만들어본 클래스~ 만든지는 꽤 되었으나~ 여지껏 새롭게 수정을 해놓지 않고 있다~
분명 분명~~~~~~~~먼가 더 좋게 만들 수 있음에도 ㅋㅋㅋㅋ 그래도 나름 쓸만해서 그냥 쓴다~
귀차니즘~ 고고싱~

package oddeye.utils 
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	/**
	 * ...
	 * @author ....
	 */
	public class DepthUtils 
	{
		
		private var _childs:Array = [];
		private var _parent:DisplayObjectContainer;
        private var _childDepths:Array = [];
		
		
		/**
		 * 뎁스 조절~
		 * @param	parent- 상위 부모객체를 등록한다.
		 */
		public function DepthUtils( parent:DisplayObjectContainer ) 
		{
			_parent = parent;
			_childs = getChilds( parent ); 
			_childDepths = getChildDepth( parent, _childs );
			
			//Debug.to(_childs);
		}
		
		public function getChildDepth( parent:DisplayObjectContainer, childs:Array ):Array
		{
			var depths:Array = [];
			for ( var i:int = 0; i < childs.length; i++)
			{
				depths.push( parent.getChildIndex( childs[i]) );
			}
			
			return depths;
		}

		/**
		 * 자식들 등록~
		 * @param	parent - 상위(부모)객체
		 * @return
		 */
		public function getChilds( parent:DisplayObjectContainer ):Array
		{
			var depthList:Array = [];
			
			for (var i:int = 0; i < parent.numChildren; i++) 
			{
				depthList.push( parent.getChildAt( i ) );
			}
			
			return depthList;
		}
		
        
		/**
		 * 뎁스를 순서대로 다시 재 정렬~
		 */
		public function resetDepth():void
		{
			var count:int = 0;
			
			for each(var child:DisplayObject in _childs)
			{
				_parent.setChildIndex( child, _childDepths[count] );
				++count;
			}
		}
		
		
		
		
		/**
		 * 뎁스를 최상위로 올려놓는다~
		 * @param	target - 최상위 뎁스를 지정할 객체
		 */
		public function setHighestDepth(target:DisplayObject):void
		{
			_parent.setChildIndex( target, _parent.numChildren - 1);
		}
		
		
		/**
		 * 뎁스를 뒤집는다.
		 */
		public function depthReverse():void
		{
			for  (  var i:int =  _childs.length-1; i >= 0; i--  )
			{
				_parent.setChildIndex(  _childs[i], _childs.length-1  );
			}
		}
		
	}

}
사용법~ 일단 주의 할 점은 우선적으로 컨테이너를 등록해야 함~
자식이 추가되는 시점에다 해당 클래스를 인스턴화시켜야 한다.
그래야 DepthUtils클래스 내부에서 자식검색시 자식이 등록이 되기에.........

아래는 짧막하게 예시.....ㅋ
   //전역에 선언
   private var _depths:DepthUtils;

   private function init():void
   {
        for( var i:int=0;i<100;i++)
        {
             container.addChild( 썸네일 );
            썸네일.addEventListener( MouseEvent.MOUSE_OVER, onOver );
            썸네일.addEventListener( MouseEvent.MOUSE_OUT, onOut );
        }
        _depths=new DepthUtils( container );
   }

   private function onOver( e:MouseEvent ):void
   {
         _depths.setHighestDepth( DisplayObject( e.currentTarget ) );
   }

   private function onOut( e:MouseEvent ):void
   {
        _depth.resetDepth();
   }
728x90
반응형
댓글