Copy link to clipboard
Copied
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!
Hi.
HTML5 or AS3?
You can use the getObjectsUnderPoint method in both languages.
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
Copy link to clipboard
Copied
Hi.
HTML5 or AS3?
You can use the getObjectsUnderPoint method in both languages.
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
Copy link to clipboard
Copied
perfect, that is exactly what I was missing! Went the long route to achieve this result. Thank you very much!
Copy link to clipboard
Copied
Excellent!
You're welcome!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now