我刚刚更新到flash player 11.2,它允许收听MouseEvent.RIGHT_MOUSE_UP和MouseEvent.RIGHT_MOUSE_DOWN。
我遇到的问题是这些事件与其MOUSE_UP / MOUSE_DOWN对应物的行为不同。具体来说,无论鼠标在哪里,都会启动MOUSE_UP事件。这允许在闪存窗口外拖动并且仍然具有完全向下 - >每当用户点击Flash播放器时,就会启动事件循环。
但是,RIGHT_MOUSE_UP / DOWN似乎不是这种情况。当我右键单击播放器并在播放器外部释放时,我没有得到RIGHT_MOUSE_UP事件,这意味着可以在不接收UP事件的情况下接收多个RIGHT_MOUSE_DOWN事件。
是否有一个已知的解决方法或是否有必须设置的选项?
修改:
这是一个代码示例:
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addeventListener(MouseEvent.RIGHT_MOUSE_UP, onRightMouseUp);
stage.addeventListener(MouseEvent.RIGHT_MOUSE_DOWN, onRightMouseDown);
//...
//all callback function follow a similar format as :
private function onMouseUp(e : MouseEvent) : void
{
leftClick_ = false;//signaling that leftClick is not pressed
}
答案 0 :(得分:2)
你可以在鼠标离开舞台时收听,这可以作为RIGHT_CLICK_UP
事件的代理。
package
{
//Imports
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
//Class
[SWF(width="640", height="480", frameRate="60", backgroundColor="0x555555")]
public class RightClickTest extends Sprite
{
//Constructor
public function RightClickTest()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
addEventListener(Event.ADDED_TO_STAGE, init);
}
//Initialize
private function init(event:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
stage.addEventListener(MouseEvent.RIGHT_MOUSE_DOWN, mouseRightClickEventHandler);
stage.addEventListener(MouseEvent.RIGHT_MOUSE_UP, mouseRightClickEventHandler);
stage.addEventListener(Event.MOUSE_LEAVE, mouseLeaveEventHandler);
}
//Mouse Right Click Event Handler
private function mouseRightClickEventHandler(event:MouseEvent):void
{
switch (event.type)
{
case MouseEvent.RIGHT_MOUSE_DOWN: trace("Right Mouse Down");
break;
case MouseEvent.RIGHT_MOUSE_UP: trace("Right Mouse Up");
}
}
//Mouse Leave Event Handler
private function mouseLeaveEventHandler(event:Event):void
{
trace("Mouse Leave");
}
}
}
但是,如果您试图避免允许用户显示多个右键单击上下文菜单(或类似的东西),您可以在代码中实现一个简单的检查,以便在显示之前隐藏可见的右键单击上下文菜单新的。