0

I am adding a canvas on top of a Haxe HTML5 Game. But once I do, the buttons in the Haxe game no longer register the click events. Does anyone know in the Haxe/openFL compiled code where the click events are being handled?

My best guess is that they are looking at the top most canvas, which is now mine and therefore not seeing the hits.

EDIT:

Found this code where the mouse events were being added to the canvas:

while(_g2 < mouseEvents.length) {
    var type2 = mouseEvents[_g2];
    ++_g2;
    element1.addEventListener(type2,$bind(this,this.element_onMouse), true);
}  

Where element1 = the canvas.

I can't seem to send $(canvas).click() events to that canvas. Anyone have further suggestions?

Greg B.
  • 1
  • 3
  • no but you can just set in css `pointer-events:none;` on your canvas (see http://stackoverflow.com/questions/1009753/pass-mouse-events-through-absolutely-positioned-element ) and it should work as expected. Question should be "Do I really need 2 canvas elements?" ^^ – Winchestro Jan 25 '15 at 00:43
  • Unfortunately that wont work. Yes, I need two canvas elements at this point. Maybe I can rework it later. I am creating a chrome with controls to an existing website that has almost 700 HTML5/Flash and Unity games already existing on it. So to make it work on all of them I am just going to keep my code separate from theirs, which has buttons that need to be active while allowing their buttons to still be active as well. – Greg B. Jan 25 '15 at 02:13
  • And the Chrome works on top of other HTML5 games that were not created in HaXe. – Greg B. Jan 25 '15 at 02:14
  • I highly doubt haxe is accidentally attaching event listeners to the wrong canvas element. that would be a huge blunder. is it working correctly if you add your canvas to the dom after haxe has set up its event listeners? – Winchestro Jan 25 '15 at 02:25
  • My canvas appears long after theirs is created. If I edit the HTML while the site is active, and delete my canvas it accepts the clicks again. – Greg B. Jan 25 '15 at 03:14
  • I am going throw the HaXe/openFL generated code right now, 20,000+ lines, to try and figure out where the eventListeners are and what they are listening for. I feel like I am getting close. – Greg B. Jan 25 '15 at 03:15

1 Answers1

0

My conclusion is, I was using JQuery to send calls to event listeners that were added through plain JavaScript.

document.getElemntById("canvas").addEventListener("mousedown", func...);

Apparently the JQuery calls can not call non JQuery events.

$(canvas).mousedown();   // does not work

Using

document.getElemntById("canvas").dispatchEvent(event) r

and sending MouseEvents to the Haxe canvas worked fine.

Gama11
  • 31,714
  • 9
  • 78
  • 100
Greg B.
  • 1
  • 3