开发者

How do I limit the following cursor to a specific area

I have a flash cs3 file where I want a mask to move on the y axis (up and down) when the user is scrolling over the navigation area.

In my code, I have:

maskMC.startdrag();

How do I limit the area where the mask will move, then make it return it back to it's original position 开发者_StackOverflow社区when the user moves away from the specific area (in this case the navigation).


1) Limiting mask drag to Y axis:

Just use the startDrag's second argument (bounds:Rectangle).

// startDrag method details
startDrag(lockCenter:Boolean = false, bounds:Rectangle = null):void

give it a Rectangle that it should use as its bounds. Details and examples can be found on Adobe's livedocs. For example, to lock dragging to only the Y axis, you should make the width of your Rectangle equal to 0.

var dragBounds:Rectangle = new Rectangle(startX, startY, 0, dragHeight);
myMask.startDrag(false, dragBounds);

2) Return mask to original Y, on drop:

The easiest way is to listen to the mouseup event on the stage. when this fires and you are dragging the mask, then set the mask y to its original location. Personally I would use Tweener to send the mask back, but you can do it how you like (possibly on enterFrame).

public function Main() 
{
    stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
}

private function mouseUpHandler(e:MouseEvent):void 
{
    if (draggingMask)
    {
        Tweener.addTween(myMask, { y:originalY, time:0.5, transition:"easeOutQuad" });
        draggingMask = false;
    }
}

You will need to set draggingMask to true when you start dragging the mask, and to false when you release it. You will also need a variable to store the original location (I used "originalY" in my example above).


to use the bounds of the drag, use the following (remembering to import flash.geom.Rectangle;)

startDrag(lockCenter, new Rectangle(leftCornerx, leftCornery, width, height))

if you want it to move back on moving out of the menu object then you want to either use a MouseEvent.ROLL_OUT or MouseEvent.MOUSE_MOVE event listener and test stage.mouseX/stage.mouseY, or run a hitTest. depends on how you have it set up on the stage.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜