How to handle mouseEvent transparently in AS3?

I have a DisplayObject docked at the top of my interface, which displays debugging information (frames per second, etc.) and is translucent with 60% alpha.

I would like to interact with the elements beneath this surface, so when the mouse rolls over it, it dims to 10% alpha, and the mouse events pass through it to the base objects.

Typically, I have this mouseEnabled and mouseChildren debugging info panel set to false, so the objects below it receive mouse events.

The problem is that in order to hide it when the mouse flips it, it must have the mouseEnabled value for true. However, if mouseEnabled is true, mouse events are not picked up by the objects below it.

As far as I know, I cannot selectively activate mouseEvents, so it will either receive them all, or none of them. This means that I will have to process and forward ALL events if I accept this approach.

I really want the mouseEnabled property to have "peek" mode or something like that, so that it can receive events if it is on top, but also allows them to pass through the objects below it.

+4
source share
6 answers

If DisplayObject has mouseEnabled=true , this means that its events will be sent to its container , and not whateve located under the object. So this solution will not work. A better solution would be to redirect events from it manually using getObjectsUnderPoint , as described here .

I have been using this approach for many years in multi-touch applications. With a few touch points, I don't see the processor overhead. And you have only one cursor.

+1
source

I believe you are looking for mouseEnabled = false
But another attempt at the last ditch you can do is move your mouse over the other side of the screen.

0
source

I feel your pain. Unfortunately, I do not know how to enable / disable certain mouse events. However, you can be creative in solving. For example, try adding a MOUSE_MOVE listener to the scene and tracing the coordinates of the mouse. Then, if stageX,stageY mouse is in the area of ​​your panel, set the visibility. You can also use getObjectsUnderPoint() to determine which objects are under the mouse. But, in my opinion, the processor will work a little more intensively at each iteration of the frame.

0
source

One approach that you can take, although not ideal, is to add an input frame receiver and check the position of the mouse in each frame. sort of:

 stage.addEventListener(Event.ENTER_FRAME, onEnterFrame); private function onEnterFrame(e:Event):void { if(mouseX > width || mouseY > height){ //hide stats } } 
0
source

I assume you have this display hierarchy:

 Debug Window Debug Control 1 Debug Control 2 ... Overlay 

Why not mask the DebugWindow and snap the mouse to DebugWindow? See this page for some inspiration: http://blog.shaperstudio.com/2010/11/as3-inverse-mask/

0
source

I had the same problem. I made a function to check the mouse over a specific object:

  public function isMouseOverObject(mPos: Point, pObject:DisplayObject, pContainer:DisplayObjectContainer) { var under_objects:Array = pContainer.getObjectsUnderPoint(mPos); var is_under:Boolean = false; for (var i:int = 0; i < under_objects.length; i++) { if (under_objects[i] == pObject) { is_under = true; break; } } return is_under; } 
0
source

Source: https://habr.com/ru/post/1400478/


All Articles