package nhn.util
{
import flash.display.*;
import flash.events.*;
import flash.geom.*;
public class ScrollManager extends MovieClip
{
public var n_mc:MovieClip;
private var npDownFlag:Boolean;
public var bar:MovieClip;
private var viewWidth:Number;
private var minX:Number;
private var maxX:Number;
private var targetWidth:Number;
private var isDrag:Boolean;
public var moveTarget:Function;
public var p_mc:MovieClip;
public var thisWidth:Number;
private var clickState:Number;
public var back:MovieClip;
public function ScrollManager(param1:uint = 0, param2:uint = 0)
{
isDrag = false;
if (param1 != 0 && param2 != 0)
{
viewWidth = param1;
targetWidth = param2;
thisWidth = this.height - n_mc.height - p_mc.height - 2;
minX = p_mc.y + p_mc.height + 1;
maxX = n_mc.y--;
setInit();
}
return;
}// end function
public function setBarCenter()
{
this.bar.y = Math.round((this.height - this.bar.height) / 2);
checkBarX();
return;
}// end function
private function backDown(event:MouseEvent) : void
{
var _loc_2:* = undefined;
_loc_2 = event.currentTarget;
if (_loc_2.mouseY < bar.y)
{
bar.y = bar.y - bar.height;
checkBarX();
}
else if (_loc_2.mouseY > bar.y + bar.height)
{
bar.y = bar.y + bar.height;
checkBarX();
}
return;
}// end function
private function pUp(event:Event)
{
var _loc_2:* = undefined;
p_mc.removeEventListener(Event.ENTER_FRAME, moveBar, false);
_loc_2 = thisWidth - bar.height;
return;
}// end function
public function setBarX(param1)
{
var _loc_2:* = undefined;
_loc_2 = thisWidth * param1 / targetWidth;
bar.y = _loc_2 + 15;
return;
}// end function
private function pDown(event:Event)
{
p_mc.addEventListener(Event.ENTER_FRAME, moveBar, false, 0, true);
npDownFlag = true;
return;
}// end function
private function barUp(event:Event)
{
var _loc_2:* = undefined;
if (isDrag)
{
this.bar.stopDrag();
this.stage.removeEventListener(MouseEvent.MOUSE_UP, barUp, false);
this.stage.removeEventListener(MouseEvent.MOUSE_MOVE, staDrag, false);
_loc_2 = thisWidth - bar.height;
isDrag = false;
}
return;
}// end function
private function nDown(event:Event)
{
n_mc.addEventListener(Event.ENTER_FRAME, moveBar, false, 0, true);
npDownFlag = false;
return;
}// end function
private function onOver(event:Event)
{
var _loc_2:* = undefined;
_loc_2 = event.currentTarget;
if (_loc_2.name == "bar")
{
_loc_2 = _loc_2.bg;
}
_loc_2.gotoAndStop(2);
return;
}// end function
private function barDown(event:MouseEvent)
{
isDrag = true;
clickState = event.currentTarget.parent.mouseY;
this.stage.addEventListener(MouseEvent.MOUSE_UP, barUp, false, 0, true);
this.bar.startDrag(false, new Rectangle(0, 15, 0, thisWidth));
this.stage.addEventListener(MouseEvent.MOUSE_MOVE, staDrag, false, 0, true);
return;
}// end function
private function addEvent()
{
back.addEventListener(MouseEvent.MOUSE_DOWN, backDown, false, 0, true);
bar.mouseChildren = false;
bar.addEventListener(MouseEvent.MOUSE_OVER, onOver, false, 0, true);
bar.addEventListener(MouseEvent.MOUSE_OUT, onOut, false, 0, true);
bar.addEventListener(MouseEvent.MOUSE_DOWN, barDown, false, 0, true);
n_mc.addEventListener(MouseEvent.MOUSE_OVER, onOver, false, 0, true);
n_mc.addEventListener(MouseEvent.MOUSE_OUT, onOut, false, 0, true);
n_mc.addEventListener(MouseEvent.MOUSE_DOWN, nDown, false, 0, true);
n_mc.addEventListener(MouseEvent.MOUSE_UP, nUp, false, 0, true);
p_mc.addEventListener(MouseEvent.MOUSE_OVER, onOver, false, 0, true);
p_mc.addEventListener(MouseEvent.MOUSE_OUT, onOut, false, 0, true);
p_mc.addEventListener(MouseEvent.MOUSE_DOWN, pDown, false, 0, true);
p_mc.addEventListener(MouseEvent.MOUSE_UP, pUp, false, 0, true);
return;
}// end function
private function setInit()
{
var _loc_1:* = undefined;
_loc_1 = thisWidth * viewWidth / targetWidth;
this.bar.bg.height = _loc_1;
this.bar.icon.y = Math.round((_loc_1 - this.bar.icon.height) / 2);
addEvent();
return;
}// end function
private function moveBar(param1)
{
if (!npDownFlag)
{
bar.y = bar.y + 10;
}
else
{
bar.y = bar.y - 10;
}
checkBarX();
return;
}// end function
private function staDrag(event:MouseEvent)
{
checkBarX();
return;
}// end function
private function nUp(event:Event)
{
var _loc_2:* = undefined;
n_mc.removeEventListener(Event.ENTER_FRAME, moveBar, false);
_loc_2 = thisWidth - bar.height;
return;
}// end function
public function setSize(param1:uint = 0, param2:uint = 0) : void
{
viewWidth = param1;
targetWidth = param2;
this.back.height = param1;
this.n_mc.y = this.back.height - this.n_mc.height;
thisWidth = this.height - n_mc.height - p_mc.height - 2;
trace("thisW == " + thisWidth);
minX = p_mc.y + p_mc.height + 1;
maxX = n_mc.y--;
setInit();
return;
}// end function
private function checkBarX()
{
var sX:*;
var vW:*;
bar.y = Math.round(bar.y);
if (bar.y < minX)
{
bar.y = minX;
}
else if (bar.y + bar.height > maxX)
{
bar.y = maxX - bar.height;
}
sX = bar.y - (p_mc.height + 1);
vW = thisWidth - bar.height;
try
{
moveTarget(sX, vW);
}
catch (e)
{
}
return;
}// end function
private function onOut(event:Event)
{
var _loc_2:* = undefined;
this.stage.removeEventListener(MouseEvent.MOUSE_MOVE, staDrag, false);
_loc_2 = event.currentTarget;
if (_loc_2.name == "bar")
{
barUp(null);
_loc_2 = _loc_2.bg;
}
_loc_2.gotoAndStop(1);
return;
}// end function
public function wheelEvent(param1)
{
bar.y = bar.y - param1 * 2;
checkBarX();
return;
}// end function
}
}
댓글 없음:
댓글 쓰기