Since your listeners are referencing the Rectangle only, just identify it by its instance name and NOT event.target. Now you can apply the same addEventListner() method to the Square, and the Rectangle will be acted upon, in either case, by the listener function.
Actionscript 3 - Making one MovieClip the hitArea of another
-
13-10-2022 - |
Question
Suppose I have a rectangle whose instance name is
rectangle
and suppose I have a square right beside the rectangle and the squares instance name is
square
. Now, I want the rectangle to hitArea to be it's own area as well as the square's area. So, if I have these three event listeners:
rectangle.addEventListener(MouseEvent.CLICK, rectangleClick);
rectangle.addEventListener(MouseEvent.MOUSE_OVER, rectangleHover);
rectangle.addEventListener(MouseEvent.MOUSE_OUT, rectangleOut);
How do I make it so that when I hover over, hover out of and click the rectangle OR square, the rectangle event listeners get called?
Note: the event listeners have
event.target
and
event.currentTarget
so I cannot do a simple
square.addEventListener(MouseEvent.CLICK, rectangleClick);
since I need the rectangle to be the
event.target
.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow