通过alt +鼠标单击在FLEX中启动MapMouseEvent

时间:2012-04-03 21:23:27

标签: flex flash-builder

我想通过键盘快捷键和鼠标点击组合启动MapMouseEvent。这是我所拥有的一部分,我不确定逻辑是否正确:

private function MapClick(event:MapMouseEvent):void 
  {
    if (event.altKey) altPressed = true;
        {
           Alert.show("Alt key has been pressed - click on screen");
           // launch the function here
        }
    else
        {
           Alert.show(" Must click Alt key first, then click on map");
        }
  }

我在这个网站上看过类似的例子,但仍未找到任何解决方案。我希望有人知道FLEX可以帮我基本上通过一系列键盘快捷键启动功能。例如:Alt +鼠标单击,或Shift +鼠标单击,或沿这些行的某些内容。原因是只需点击一下鼠标就可以在屏幕上显示其他内容。

谢谢...

RJ

1 个答案:

答案 0 :(得分:0)

您提供的代码非常接近正确。

private function MapClick(event:MapMouseEvent):void 
  {
    if (event.altKey);
        {
           //This means alt is held, AND a click occurred.
           //run function for alt-click here
        }

    if (event.ctrlKey);
        {
           //This means ctrl is held, alt was *not* held, AND a click occurred.
           //run function for ctrl-click here
        }

    if (!event.ctrlKey && !event.altKey)
        {
           //this means that a click occurred, without the user holding alt or ctrl
           //run function for normal click here.
        }
  }

我写这个的方式,如果用户持有ctrl + alt并点击,BOTH函数就会运行。如果你想让alt优先于ctrl或类似,下面的代码将起作用。

private function MapClick(event:MapMouseEvent):void 
  {
    if (event.altKey);
        {
           //This means alt is held, AND a click occurred.
           //run function for alt-click here
        }
    else if (event.ctrlKey);
        {
           //This means ctrl is held, AND a click occurred.
           //run function for ctrl-click here
        }
    else
        {
           //this means that a click occurred, without the user holding alt or ctrl
           //run function for normal click here.
        }
  }