Copy link to clipboard
Copied
Is it possible in AS3 to have a left click mouse function to drag and holding control key + click to do something else?
Thank you,
arofa
Hi.
You can do something like this:
...import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.MouseEvent;
var ctrl:Boolean = false;
var mouseDown:Boolean = false;
function start():void
{
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseHandler);
stage.addEventListener(MouseEvent.MOUSE_UP, mouseHandler);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseHandler);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
stage.addEventListener(KeyboardEvent.KEY_U
Copy link to clipboard
Copied
Hi.
You can do something like this:
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.MouseEvent;
var ctrl:Boolean = false;
var mouseDown:Boolean = false;
function start():void
{
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseHandler);
stage.addEventListener(MouseEvent.MOUSE_UP, mouseHandler);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseHandler);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
}
function mouseHandler(e:MouseEvent):void
{
if (e.type == MouseEvent.MOUSE_DOWN)
mouseDown = true;
else if (e.type == MouseEvent.MOUSE_UP)
mouseDown = false;
if (e.type == MouseEvent.MOUSE_MOVE)
{
if (ctrl && mouseDown)
trace("ctrl + dragging");
}
}
function keyHandler(e:KeyboardEvent):void
{
if (e.type == KeyboardEvent.KEY_DOWN)
{
if (e.keyCode == Keyboard.CONTROL)
ctrl = true;
}
else if (e.type == KeyboardEvent.KEY_UP)
{
if (e.keyCode == Keyboard.CONTROL)
ctrl = false;
}
}
start();
I hope it helps.
Regards,
JC
Copy link to clipboard
Copied
Thank you very much for your help João César, that is what I needed
Arofa
Copy link to clipboard
Copied
Excellent!
You're welcome!
Copy link to clipboard
Copied
I'm not sure if JC's idea will work out, but there is already a context menu system in place, since Flash 9. Here's the documentation:
Find more inspiration, events, and resources on the new Adobe Community
Explore Now