Launch MapMouseEvent in FLEX via alt + mouse click

Go To StackoverFlow.com

0

I would like to launch a MapMouseEvent via a combination of keyboard short cuts and a mouse click. This is a portion of what I have, and I am not sure if the logic is correct:

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");
        }
  }

I have looked at similar examples on this site but still have not reach any solution. I am hoping that someone who knows FLEX can help me to basically launch a function via a series of Keyboard shortcut. For example: Alt + mouse click, or Shift + mouseclick, or something along those lines. The reason is that a simple mouse click already does something else on the screen.

Thanks ...

RJ

2012-04-03 21:23
by Randall Sounhein


0

The code you've provided is very close to correct.

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.
        }
  }

The way I wrote this, if a user holds ctrl+alt and clicks, BOTH functions run. If you'd rather have alt have priority over ctrl, or similar, the below code will work.

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.
        }
  }
2012-04-11 18:45
by Sam DeHaan
Hey Sam: Thanks for the reply. I have been off line a bit (late reply) so sorry about that. Yeah I should of know better to exclude the else statements here. Ok will check it out to see if I can get it going .. - Randall Sounhein 2012-04-17 18:01
Ads