我一直无法创建一种机制,允许用户从时间线中选择一段时间。基本上我希望他们能够水平点击和拖动,并检索该事件的开始和结束位置。
我特别需要包括事件离开屏幕边缘的情况(即使结束位置被捕捉到屏幕边缘也没关系)。
在完成所有这些操作时,我希望能够绘制一个从事件开始到鼠标当前位置的框,以便明确选择哪个区域。
答案 0 :(得分:3)
基本上,在我看来,你不是在拖东西。你只需要一系列的按压,移动和释放。你必须点击某些东西,我打赌你可以考虑时间轴上的新闻事件。所以它会像:
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);