Mouse events from 2 Canvas

Tuesday, September 25th, 2007

Maybe 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?

Flex example: 2 Canvas Mouse events

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.

Source Code

And what I need is have possibility to catch both events in same time.
Can this be done? Anyone?

Thanks

AddThis Feed Button

This is some text prior to the author information. You can change this text from the admin section of WP-Gravatar  I'm living in Bratislava, Slovakia. I'm Senior Flex, AIR Developer for my own company Flexets. Read more from this author


tagged under:

ABOUT THIS AUTHOR

I'm living in Bratislava, Slovakia. I'm Senior Flex, AIR Developer for my own company Flexets.

Get a Trackback link

7 Comments


  1. 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.


  2. 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


  3. 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.


  4. 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.


  5. 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 :)


  6. Tink
    Visit Site
    September 26th, 2007

    Senocular’s VirtualMouse class will work for ya

    http://www.senocular.com/demo/VirtualMouse/VirtualMouse.html


  7. 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

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

This site is using OpenAvatar based on
Images is enhanced with WordPress Lightbox JS by Zeo
Clicky Web Analytics