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

clicking 2 overlapping buttons at once

Participant ,
Nov 29, 2018 Nov 29, 2018

Hello!  I am wondering if anyone can suggest a simpler solution to this, perhaps I'm overlooking something. 

I have several elements used as buttons, some of them overlap.  If I click on the overlapping elements, they both need to trigger their respective functions.  By default, only the top element will register a click, and the one underneath will not.

My solution was as follows:

Rather than assign click event listeners, I store nominal bounds of all buttons and on click check if my mouse position falls inside any of them.  If yes, I trigger the function for anything that's hit. 

This works, but it seems very overengineered.  Is there a simpler way to do this?

Thank you!

698
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 , Nov 29, 2018 Nov 29, 2018

Hi.

HTML5 or AS3?

You can use the getObjectsUnderPoint method in both languages.

HTML5 | AS3

Here is a HTML5 example:

stage.on("stagemousedown", function(e)

{

    var pressedObjects = e.currentTarget.getObjectsUnderPoint(e.stageX, e.stageY);

    pressedObjects.forEach(function(object)

    {

          object.alpha = 0.25;

    });

});

Regards,

JC

Translate
Community Expert ,
Nov 29, 2018 Nov 29, 2018

Hi.

HTML5 or AS3?

You can use the getObjectsUnderPoint method in both languages.

HTML5 | AS3

Here is a HTML5 example:

stage.on("stagemousedown", function(e)

{

    var pressedObjects = e.currentTarget.getObjectsUnderPoint(e.stageX, e.stageY);

    pressedObjects.forEach(function(object)

    {

          object.alpha = 0.25;

    });

});

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
Participant ,
Dec 03, 2018 Dec 03, 2018

perfect, that is exactly what I was missing!  Went the long route to achieve this result.  Thank you very much!

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 ,
Dec 03, 2018 Dec 03, 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