【问题标题】:ActionScript drag limit, backwards?ActionScript 拖动限制,向后?
【发布时间】:2011-09-12 20:50:01
【问题描述】:

我有一个应用程序,用户在其中上传图像,然后通过单击、拖动和使用调整大小栏对其进行转换。但是我的客户要求我限制用户可以拖动到的位置,这不是问题,除非我需要与正常情况相反的限制。

所以我有 startDrag(false, new Rectangle...) 工作得很好,但我需要的是让用户能够拖动边界之外并且在闪光灯内部没有空白文件。

我的意思是说我有一个 500 像素宽的 flash 文件和其中的一个图像,我不小心在其中拖动。如果图像的右侧边缘(如果我向左拖动)达到 500 像素,它将停止拖动并且不允许它们向左再拉。

我真的希望我已经很好地解释了这一点,任何指导都会很棒!

以下是我目前用于拖动事件的代码。

任何帮助将不胜感激。

public function startImageDrag (e:MouseEvent):void {
        mousePos['x'] = e.target.mouseX;
        mousePos['y'] = e.target.mouseY;
        imageDraggable.removeEventListener(MouseEvent.MOUSE_DOWN, function ():void {});
        photoapp.cStage.addEventListener(MouseEvent.MOUSE_MOVE, moveImage);
        photoapp.cStage.addEventListener(MouseEvent.MOUSE_UP, endImageDrag);
    }
    //The type is wildcarded because I have this hooked to MOUSE_LEAVE too
    public function endImageDrag (e:*):void {
        photoapp.cStage.removeEventListener(MouseEvent.MOUSE_MOVE, moveImage);
        photoapp.cStage.addEventListener(MouseEvent.MOUSE_DOWN, startImageDrag);
    }

    public function moveImage(event:MouseEvent):void {
        //Get the offset of the current mouse position over the image
        var
            //The mouse position on the stage
            sxOff:Number = photoapp.cStage.mouseX,
            syOff:Number = photoapp.cStage.mouseY,
            //The position on which the mouse down event was on the image
            reX:Number = sxOff - mousePos['x'],
            reY:Number = syOff - mousePos['y'],
            //The iamge object
            i:DisplayObject = imageDraggable;

        //Move the image
        if (/*I have no idea now...*/) {
            imageDraggable.x = reX;
        }
        if (iY) {
            imageDraggable.y = reY;
        }

        event.updateAfterEvent();
    }

【问题讨论】:

    标签: flash actionscript-3 actionscript


    【解决方案1】:
    // this code will limit the movement to 100 pixels to the right
    var bounds:Rectangle = new Rectangle( 0,0,100,0)
    imageDraggable.startDrag( false,bounds );
    

    [编辑]
    也许这会帮助你更多的了解

    var boundsWidth:Number  = stage.stageWidth  - pictureHolderMC.width );
    var boundsHeight:Number = stage.stageHeight - pictureHolderMC.height );
    var bounds:Rectangle = new Rectangle(0, 0, boundsWidth, boundsHeight);
    pictureHolderMC.startDrag(false, bounds); 
    

    【讨论】:

    • 嗨,我知道该怎么做。问题询问如何将拖动目标限制在舞台边缘。即它们不能被拖到 0, 0, stage.stageWidth, stage.stageHeight 之外,因此它里面总是有内容而不是空白。
    • 矩形(0,0,stage.stageWidth-imageDraggable.width,stage.stageHeight-imageDraggable.height)
    • 抱歉,更好的解释方式是 top 和 left 只允许为负数(在舞台之外),而 bottom 和 right 只允许在 stage 尺寸之外。抱歉刚刚看到你的回答,我试试看。
    • 嗨,这限制了顶部和左侧,但我仍然可以将底部和右侧边缘拖入舞台,留下不需要的空白空间
    • 你能定义空白吗?该矩形为图像移动的 0,0 点创建了一个边界框。
    猜你喜欢
    • 2013-03-14
    • 1970-01-01
    • 2011-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-09
    • 2012-08-15
    相关资源
    最近更新 更多