Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AS3

Community Beginner ,
Feb 26, 2018 Feb 26, 2018

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

TOPICS
ActionScript
406
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 27, 2018 Feb 27, 2018

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

...
Translate
Community Expert ,
Feb 27, 2018 Feb 27, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 28, 2018 Feb 28, 2018

Thank you very much for your help João César, that is what I needed

Arofa

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 28, 2018 Feb 28, 2018
LATEST

Excellent!

You're welcome!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 27, 2018 Feb 27, 2018

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:

ContextMenu - Adobe ActionScript® 3 (AS3 ) API Reference

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines