Thursday, September 29, 2022

[FIXED] How to add detect button presses in tvOS?

Issue

I have follow this tutorial and everything works fine. The only issue I'm having is i can't figure out how to detect when a button has been pressed?

Thanks in advance


Solution

Author of the tutorial here, the method of adding interactivity to TVML-based apps is to use addEventListener on the DOM element in question. You can find the DOM element by holding a reference to it during creation, or by using getElementById or other such similar JavaScript DOM techniques. Also, I should mention I've added a "Part 2" to the mentioned tutorial which includes this as it's primary focus.

Here's an example of how you might do this in JS, assuming myDOMElement is a variable that references your button as a DOM element.

  myDOMElement.addEventListener("select", function() { alert("CLICK!") }, false);

I have more info on the tutorial of course, so feel free to check that out, too.



Answered By - Jameson
Answer Checked By - Cary Denson (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.