Time for action – Working around by storing reference to functions
You can work around this problem by storing references to functions:
import js.Lib; import js.Dom; class Main { static var but1:js.Button; static var but2:js.Button; static var myHandler:js.Event->Void; public static function main(): Void { but1 = cast Lib.document.getElementById("button1"); but2 = cast Lib.document.getElementById("button2"); myHandler = clickHandler; untyped but1.addEventListener("click", myHandler); but2.onclick = removeHandler; } public static function clickHandler(ev : js.Event) { js.Lib.alert("You've clcked."); } public static function removeHandler(ev:js.Event) { untyped but1.removeEventListener("click", myHandler); } }
What just happened?
Note the use of ...
Get haXe 2 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.