Mouse events from 2 Canvas
Tuesday, September 25th, 2007Maybe I’m missing something, but I hope this has solution. I got 2 Canvas on same level (1 can not be child of another 1). First canvas has children which are listening to the MouseEvent.MOUSE_OVER. Second canvas is listening to the UP, DOWN, MOVE Mouse Events. Problem is that when both canvas are ovelapped, bottom canvas does not catch mouse events. But when top canvas is not listening to the mouse events, bottom one can catch such events.
So => 2 overlapped canvas can not listen to mouse events. But I really need to solve this in Flex 2. Is that solution for this problem?
In this example “bottom canvas” is red one with white square. White square listen to mouse over (trace to the TextArea). Top Canvas is transparent ( has not set backgroundColor property). If you press button “Add Listener” you will add MouseEvent.CLICK to the top Canvas, so you can click on canvas (in red area, don’t forget top is transparent), and click is traced to the TextArea, but Over on white square is not working. After click on “Remove Listener” functionality is back, you can rollover white square but not click.
And what I need is have possibility to catch both events in same time.
Can this be done? Anyone?
Thanks
tagged under:






7 Comments
Dan H
• Visit Site
September 25th, 2007
Can you listen in the parent container? The mouse events should bubble upwards, where you can then catch and cancel the events from going down. You should then be able to use event.currentTarget or event.target to determine the origin of the event.
Administrator
• Visit Site
September 25th, 2007
For now, it seems that it’s problem, because I don’t know about children of bottom Canvas (in my examples it is white square). It’s maitained by another source
Tink
• Visit Site
September 26th, 2007
This is just as you would expect. You can’t have buttons inside buttons.
Instead of adding the MouseEvent.CLICK listener to your Canvas, draw a background inside it, and add the listener to that, so there the white square sts on top of it.
Might even be worth overridding addListener and removeListener so that if you do try and add listeners to the Canvas, they are automatically re-directed.
NOTE: Where the white square is on top of your background, you won’t get events from the background.
Tink
• Visit Site
September 26th, 2007
I just re-read this and think I misunderstood your explaination.
Its is what i would expect though, i.e. if you create 2 buttons that are 100 x 100. If you place the buttons on top of each other, only the top item will get mouse events, as the mouse doesn’t interect with the button at the bottom.
Administrator
• Visit Site
September 26th, 2007
Yes Tink, your second comment is right. I know that buttom button cannot interact, but im searching for workaround of that
that’s why I wrote this post in hope that someone know workaround 
Tink
• Visit Site
September 26th, 2007
Senocular’s VirtualMouse class will work for ya
http://www.senocular.com/demo/VirtualMouse/VirtualMouse.html
Naseer Fedaee
• Visit Site
September 28th, 2007
Hi,..
Good night!
So i want to see any new backgrounds from you man!
Can i?
….
Live Preview
Leave a comment