3的文本菜单关闭事件

3的文本菜单关闭事件

本文介绍了ActionScript 3的文本菜单关闭事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还有就是它被分派时的上下文菜单(右键菜单)的动作闪光事件已被打开:

There is an event which is dispatched when the context menu (right click menu) in actionscript for flash has been opened:

ContextMenuEvent.MENU_SELECT

现在,有没有当菜单已关闭其分派的事件?

Now, is there an event which is dispatched when the menu has been closed?

推荐答案

好问题。这将是一个不错的功能要求,一个ContextMenuEvent.MENU_CLOSED事件:)

Good question.That would make a nice feature request, an ContextMenuEvent.MENU_CLOSED event :)

我想我有一半你的答案。这是我的想法:

I think I have half you're answer. Here's my idea:

var myContextMenu:ContextMenu = new ContextMenu();
var menuLabel:String = "Custom Item";
var rightClicking:Boolean;

addCustomMenuItems();
myContextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, menuSelectHandler);
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseUpHandler);
    var redRectangle = makeRedRectangle();
    redRectangle.contextMenu = myContextMenu;


function makeRedRectangle():Sprite{
    redRectangle = new Sprite();
    redRectangle.graphics.beginFill(0x990000,.2);
    redRectangle.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
    redRectangle.mouseChildren = false;
    addChild(redRectangle);
    return redRectangle;
}

function addCustomMenuItems():void {
    myContextMenu.hideBuiltInItems();
     var item:ContextMenuItem = new ContextMenuItem(menuLabel);
     myContextMenu.customItems.push(item);
     item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemSelectHandler);
}

function menuSelectHandler(event:ContextMenuEvent):void {
     trace("menuSelectHandler: " + event);
     rightClicking = true;
}

function menuItemSelectHandler(event:ContextMenuEvent):void {
     trace("menuItemSelectHandler: " + event);
}

function mouseUpHandler(event:MouseEvent):void{
    if(rightClicking){
    	trace('ContextMenu Closed\nThank You! Come Again!');
    	rightClicking = false;
    }
}

基本上,我创建了一个精灵,坐在放在第一位,但设置为false mouseChildren,所以剪辑娄它可以得到的点击次数。您可能希望有这样的一个透明。我用这个,所以你得到一个触发的事件当你右键点击了它。当发生这种情况我设定rightClicking为真,这意味着,我知道右键是pressed,我只是在等待其他事情发生。有两个选项:

Basically I create a sprite that sits on top of everything, but has mouseChildren set to false, so clips bellow it can get the clicks. You might want to have this one transparent. I used this so you get an event fired when you right click over it. When that happens I set rightClicking to true, meaning, I know the right click was pressed, I'm just waiting for something else to happen. There are two options:

  1. 在用户从菜单中选择一个项目。
  2. 在用户点击即可使菜单消失。

有关选项1,如果用户选择的任何自定义项,这很酷,你可以处理,如果不是,至少你知道会发生什么事情。选项​​2我设置的侦听器MOUSE_DOWN事件,因此,如果rightClicking被开启,你必须按下鼠标,这是你的菜单中结束。

For option 1, if the user selects any of your custom items, that's cool, you can handle that, if not, at least you know what might happen.For option 2 I've setup the listener for the MOUSE_DOWN event, so if the rightClicking was turned on and you got to the mouse down, that's your menu closing.

希望这有助于!

我知道,它看起来像哈克老同学AS2,和code从文档的例子修改,但它是一个想法:)

I know, it looks like hacky old school as2, and the code is modified from the documentation example, but it's a thought :)

这篇关于ActionScript 3的文本菜单关闭事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 17:16