Interactive slider for scaling a silhouette
I am trying to build a interactive slider,in which when user drag the slider up the height of silhouette increases by some fix amount n when user drag the slider down the height of silhouette decreases by some fix amount.
the problem i am facing is that when i drag the slider slowly than everything works fine but when i drag the slider faster than the height dont increase or decrease properly.i mean the increment or decrement in the height of silhouette is depending on speed of slider,which i dnt want.
here is the code-
var bounds:Rectangle = new Rectangle(499.65,260,0,240);
slider.addEventListener(MouseEvent.MOUSE_DOWN, moveSlider);
stage.addEventListener(MouseEvent.MOUSE_UP, stopSlider);
/*****Function to move slider of height bar*****/
function moveSlider(Event:MouseEvent)
{
slider.startDrag(false,bounds);
stage.addEventListener(MouseEvent.MOUSE_MOVE, changeHeight);
slider.removeEventListener(MouseEvent.MOUSE_DOWN, moveSlider);
stage.addEventListener(MouseEvent.MOUSE_UP, stopSlider);
}
/*****Function to stop slid开发者_如何学JAVAer of height bar*****/
function stopSlider(Event:MouseEvent)
{
slider.stopDrag();
slider.addEventListener(MouseEvent.MOUSE_DOWN, moveSlider);
stage.removeEventListener(MouseEvent.MOUSE_MOVE, changeHeight);
stage.removeEventListener(MouseEvent.MOUSE_UP, stopSlider);
}
/*****Function to increase height & change values in height text box*****/
function changeHeight(Event:MouseEvent)
{
if(mouseY > 260 && mouseY < 500)
{
d = 500 - mouseY;
var m:Number = d % factor;
model_height.scaleY += .002;
model_height.scaleX += .002;
if (m == 0)
{
i++;
}
if (i > 11)
{
f++;
i = 0;
}
inches = i;
height_bottom_txt.text = f + "ft." + " " + inches + " " + "in.";
}
}
Thanks Khushwant
change the
MouseEvent.MOUSE_MOVEto
Event.ENTER_FRAMEits more accurate for detecting that kind of stuff
精彩评论