Is there something like the java 'glasspane' in as3?
在as3中有类似java'glasspane'的东西吗?
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
当您希望能够捕获事件或绘制已包含一个或多个组件的区域时,玻璃窗格非常有用。例如,您可以通过使玻璃窗格拦截事件来停用多组件区域的鼠标事件。或者,您可以使用玻璃窗格在多个组件上显示图像。 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.
为什么这样?虽然flash中正在进行一些动画制作,但我希望防止任何鼠标事件被触发。我可以系统地删除所有听众,然后在动画之后重新添加它们,但是如果有类似玻璃板的东西,它可能是一种更容易实现相同效果的方法。
My current thinking is to:
我目前的想法是:
- add a sprite to the stage
- stretch to width and height of the stage,
- give the sprite the highest z-order,
- grab all events on this sprite, and stop their propagation?
在舞台上添加一个精灵
伸展到舞台的宽度和高度,
给精灵最高的z顺序,
抓住这个精灵上的所有事件,并停止它们的传播?
2 个解决方案
#1
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.
在最顶层的DisplayObject上,它应该禁用应用程序的所有鼠标事件。我已经习惯了,它可以用来享受。
#2
For a more specific approach, e.g. only block clicks but let mouse down etc. through I use this approach. It uses a 'clickBlocker' stage event handler during capture phase, stopping propagation to any other object.
对于更具体的方法,例如通过我使用这种方法只阻止点击,但让鼠标等。它在捕获阶段使用“clickBlocker”阶段事件处理程序,停止传播到任何其他对象。
public function blockClicks():void{
if(!stage) return;
stage.addEventListener(MouseEvent.CLICK, clickBlocker, true); //useCapture!
}
private function clickBlocker(event:MouseEvent):void{
trace("Me (the stage) gets the "+event.type+" first, and I block it @"+event.stageX+"/"+event.stageY);
event.stopImmediatePropagation();
}
#1
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.
在最顶层的DisplayObject上,它应该禁用应用程序的所有鼠标事件。我已经习惯了,它可以用来享受。
#2
For a more specific approach, e.g. only block clicks but let mouse down etc. through I use this approach. It uses a 'clickBlocker' stage event handler during capture phase, stopping propagation to any other object.
对于更具体的方法,例如通过我使用这种方法只阻止点击,但让鼠标等。它在捕获阶段使用“clickBlocker”阶段事件处理程序,停止传播到任何其他对象。
public function blockClicks():void{
if(!stage) return;
stage.addEventListener(MouseEvent.CLICK, clickBlocker, true); //useCapture!
}
private function clickBlocker(event:MouseEvent):void{
trace("Me (the stage) gets the "+event.type+" first, and I block it @"+event.stageX+"/"+event.stageY);
event.stopImmediatePropagation();
}