gpt4 book ai didi

flash - 在Actionscript 3中拖动时检测鼠标离开舞台

转载 作者:行者123 更新时间:2023-12-03 14:37:05 25 4
gpt4 key购买 nike

Event.MOUSE_LEAVE在 Actionscript 3 中很棒,但如果用户按住左(或右)鼠标按钮,它似乎不会触发。

有没有办法在按住鼠标的同时检测鼠标是否离开 Flash 电影?或者如果它是在 Flash 电影之外发布的?

最佳答案

要获得所有这些需要一点点技巧。您必须存储鼠标是否离开舞台并处理Event.MOUSE_LEAVE事件相应。这样做可以为您提供所有正常的鼠标功能,包括不会因为鼠标离开舞台而停止拖动。由于用户可能会回到舞台并继续拖动,它会等待直到用户在舞台上或舞台外释放鼠标。

var mouseOffStage:Boolean;

var bonk:YourDisplayObject = new YourDisplayObject()
addChild(bonk);
bonk.addEventListener(MouseEvent.MOUSE_DOWN, function():void {
mouseOffStage = false;

bonk.startDrag();

stage.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
stage.addEventListener(Event.MOUSE_LEAVE, mouseLeave);
stage.addEventListener(MouseEvent.MOUSE_OUT, mouseOut);
stage.addEventListener(MouseEvent.MOUSE_OVER, mouseOver);
})

private function mouseUp(e:MouseEvent) :void {
trace("Mouse Up On Stage")
bonk.stopDrag()
}

private function mouseLeave(e:Event) :void {
if(mouseOffStage){
trace("mouse up and off stage");
bonk.stopDrag();
}else{
trace("mouse has left the stage");
//no reason to stop drag here as the user hasn't released the mouse yet
}
}

private function mouseOut(e:MouseEvent) :void {
mouseOffStage = true;
trace("mouse has left the stage")
}

private function mouseOver(e:MouseEvent) :void {
mouseOffStage = false;
trace("mouse has come back on stage");
}

黑客是 MOUSE_LEAVE事件,而不是 MOUSE_UP事件,在鼠标离开舞台时被触发,因此您必须跟踪鼠标在释放时是否已经离开舞台。

拖动完成后,您当然希望删除与检测鼠标移出和鼠标移开相关的所有事件监听器,但为了可读性而省略了该代码。

关于flash - 在Actionscript 3中拖动时检测鼠标离开舞台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1563434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com