How to check or print which element handle specific event - html

happy new year 2017!!
I want check which elememt is owner of event.
for example, basically mouse wheel event handler(owner) is body element.
if I had several vertical scrollbar, mouse wheel event handler will be changed.
please tell me how to print event owner(especially mouse wheel event).
Thanks!

The event Object has several properties. You are looking for currentTarget or target, depending on how you registered the event handler and which element actually called it.
You can play with them to see.

Related

How to detect menu button press in TVOS app using TVJS

I need to know when a document(screen) is popped off the stack in an Apple tvOS app. I thought detecting the Menu button press would be the simplest way, but I'm using TVJS and have not been able to figure out how to write the event handler.
Please help me write an event handler that will fire on document removal, menu button press or offer an alternative solution.
Subscribe to the event unload - it's triggered whenever a page disappears after being popped from the stack:
doc.addEventListener("unload", Presenter.onUnload.bind(Presenter));
[...]
onUnload: function(event) {
console.log("onUnload");
},
There is such thing of a handler for onDocumentRemoval or similar. What you can do, instead, is create a global select handler:
doc.addEventListener("select", self.doThing.bind(self));
And then check if the fired event comes from one of the buttons used to remove an element of the stack (let's suppose those buttons have a class named delete:
doThing: function(event){
var element = event.target;
if (element.getAttribute("class").contains("delete")){
//enter code here
}
EDIT 1:
I found the possible events the TVMLKit handles (I know it is in Swift/Objective-C, but the events are the same):
TVElementTypePlay
A play event has been dispatched.
TVElementTypeSelect
A select event has been dispatched.
TVElementTypeHoldSelect
A hold event has been dispatched.
TVElementTypeHighlight
A highlight event has been dispatched.
TVElementTypeChange
A change event has been dispatched.
Those events are only attachable to a template as far as I could test. I guessed the change event would be perfect if I could attach it to the navigationDocument to listen for changes, but those two options won't work and both fire errors:
Attached to the global:
navigationDocument.addEventListener("change", function(event){console.log(event)});
Attached to the documents array:
navigationDocument.documents.addEventListener("change", function(event){console.log(event)});
There is no built-in method for those above to listen for any change. The event, though, will work on a template listening to internal changes. But it won't fire when the template is pushed to or popped from the stack.
I am guessing you will need to re-design your app in order to achieve what you are looking for.

AS3 - Detect if mouse is down, even if overlaps

I would like to know if the mouse button is down, even if another object is being clicked. How do I do that? Simply adding event listeners doesn't work as it does not trigger if something else is on top of the object.
Thanks
Add both a Click & MouseDown event listeners to the stage.
If an object is clicked , the event will bubble up to the stage so you should be able to register it and react accordingly.
You can also check the event.currentTarget property to find out where the event originated from , this should tell you if it was the stage or an object being clicked as well as where the mouse down event came from.
Add a mouse down event listener to the stage (or other parent of all objects in question)

Behavior of MOUSE_OVER eventListener in action-script-3

If the mouse is over an object before and while a MOUSE_OVER event is registered, does it trigger? I ask this because it appears that it doesn't in my program, and I want to know if this is a universal behavior of all MOUSE_OVER events. Is there a way around this?
I'm gonna avoid giving a code example here, because my program is large and complicated.
The MOUSE_OVER event will dispatch whenever the cursor enters the bounds of any interactive DisplayObject, such as a Sprite or MovieClip; this includes any of its children (see ROLL_OVER if you wish to ignore children).
As well, the event will dispatch in cases where an object is added to the stage and currently happens to be under the cursor.
It is important to make sure that your event listener has been registered before the Flash Player has dispatched the event -- system events are not queued beyond a single frame, and thus no handlers will be invoked for previous activity.

Listen to click event on overlapped sprites

I have two sprites in my movieclip, one under the other, and i want both to listen to mouse clicks event.
I found that only the top level sprite receives the event when i click on it.
I need to dispatch the events on both, so I can't use mouseenabled=false.
Is there a simple workaround for this?
Another solution is, that you listen to the click-event on the upper sprite, and fire it again with
dispatchEvent(new MousEvent(event));
Have a look at the "bubble" property of the event.
You can use the 'getObjectsUnderPoint' method native to the DisplayObjectContainer
You can see how it works here:
http://snipplr.com/view/34945/as3-trace-movieclips-under-mouse/
and the AS3 reference here:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html
You would listen on the stage for any click event and if one occurs, check to see if the element you require is under that click position.

'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:
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?
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.
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.
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();
}