【问题标题】:Creating drag bar purely in actionscript纯粹在动作脚本中创建拖动条
【发布时间】:2010-07-16 13:56:35
【问题描述】:

我在创建一种允许用户从时间轴中选择时间跨度的机制时遇到了麻烦。基本上我希望他们能够单击并水平拖动,并检索该事件的开始和结束位置。

我特别需要包括事件超出屏幕边缘的情况(即使结束位置捕捉到屏幕边缘也可以)。

在执行所有这些操作的同时,我希望能够绘制一个从事件开始到鼠标当前位置的框,这样如果选中哪个区域就很明显了。

【问题讨论】:

    标签: apache-flex flash actionscript-3


    【解决方案1】:

    基本上,在我看来,您并没有在拖什么东西。您只需按顺序按、移动和释放。你必须点击一些东西,我敢打赌你可以考虑时间轴上的新闻事件。所以它会是这样的:

    timeline.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
    timeline.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
    // the next line just considers that leaving the object surface is the same as depressing the mouse button
    timeline.addEventListener(MouseEvent.MOUSE_OUT, onMouseUp);
    
    function onMouseDown(evt:MouseEvent):void {
        // add the event listener for the mouse move action
        timeline.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
        // create the movie clip for the box
        // you get the mouse coordinates from evt.localX and evt.localY (relative to the origin of the timeline movieclip) or evt.stageX and evt.stageY (as global values)
    }
    
    function onMouseMove(evt:MouseEvent):void {
        // adjust the selection width and height
        // you get the mouse coordinates from evt.localX and evt.localY (relative to the origin of the timeline movieclip) or evt.stageX and evt.stageY (as global values)
    }
    
    function onMouseUp(evt:MouseEvent):void {
        // remove the event listener for the mouse move, that means that the function onMouseMove will no longer be called
        timeline.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
        // brush up and send the final coordinates of the selection to the next function
    }
    

    对于选择图形本身,您可以使用库中的影片剪辑实例,也可以简单地创建一个空影片剪辑,使其半透明并在其中绘制一个矩形,如下所示:

    var selection:MovieClip = new MovieClip();
    selection.alpha = 0.5;
    selection.graphics.beginFill(0x000000);
    selection.graphics.drawRect(x,y,width,height);
    selection.graphics.endFill();
    this.addChild(selection);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-25
      • 1970-01-01
      • 2012-02-24
      • 2020-03-12
      • 1970-01-01
      • 2015-10-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多