Thursday, March 31, 2011

'glasspane' for as3 to intercept events to everything on stage?

Is there something like the java 'glasspane' in as3?

The glass pane is useful when you want to be able to catch events or paint over an area that already contains one or more components. For example, you can deactivate mouse events for a multi-component region by having the glass pane intercept the events. Or you can display an image over multiple components using the glass pane. http://java.sun.com/docs/books/tutorial/uiswing/components/rootpane.html

Why do this? While some animations are underway in flash, I want to prevent any mouseevents from firing. I could remove all listeners systematically, then re-add them after the animation, but if there is something like a glasspane, it might be an easier way to achieve the same effect.

My current thinking is to:

  1. add a sprite to the stage
  2. stretch to width and height of the stage,
  3. give the sprite the highest z-order,
  4. grab all events on this sprite, and stop their propagation?
From stackoverflow
  • if you set

    enabled=false;
    mouseChildren=false;
    

    on to the top most DisplayObject it should disable all mouse events for your app. I've used it and it works a treat.

    jedierikb : Thanks! I see mouseChildren and tabChildren in DisplayObjectContainer... setting them to false works. But where is enabled?
    James Hay : Apppologies... enabled is a flex thing on UIComponnet. You may need to set mouseEnabled to false though to stop mouse events on the main clip, but if it's the root level i doubt it's necessary

0 comments:

Post a Comment