triggerServerEvent trouble

Hi all,

Thanks to Greg I’ve advanced a lot with the exploration of the WebControlWrapper. I’m trying to write some kind of game engine with it and the graphics are going very well. But now interaction is needed, and I’m stuck trying all day I’m afraid…

I’m trying to receive a mouse down event from my WebControlWrapper.

Here is the relevant code of my latest trial in SetupJavascriptFramework:

  s.Append "XojoCustom.alwaysbusy.abwebcanvas.initialize = function initialize(cControlID, cWidth, cHeight) {"
  s.Append "    width=cWidth;"
  s.Append "    height=cHeight;"
  s.Append "    controlID=cControlID;"
  s.Append "    var tmpView;"
  s.Append "    tmpView = document.getElementById(controlID);"
  s.Append "    tmpView.addEventListener('mousedown', function(event) {"
  s.Append "        var x = event.pageX;"
  s.Append  "       var y = event.pageY;"
  s.Append "        console.log('x:' + x + ',y:' + y);"
  s.Append "        Xojo.triggerServerEvent(controlID, 'mousedown', [x,y]);"
  s.Append "    }, false);"
  s.Append "};"

in ExecuteEvent: (but this is never triggered, at least the breakpoint is never reached)

  select case Name
  case "mousedown"
    Return MouseDown(Parameters(0), Parameters(1))
  end select

The MouseDown event definition:

Event MouseDown(x as integer, y as integer) As Boolean

The event on the control on the webpage:

Function MouseDown(x as integer, y as integer) As Boolean
  MsgBox str(x)
End Function

I see the correct ‘console.log()’ in the console when I click on the webcontrol and Xojo must receive something, as the debugger goes in pauze but does not enter the ExecuteEvent() handler. When I press play it continues and I can click again with the same result.

Anyone who can shine some light on triggerServerEvent (and triggerBrowserEvent) as the 8 lines in the WebSDK documentation are not a big help, nor a google search on ‘Xojo triggerServerEvent’ or the examples.

(Windows 7, Firefox in case it matters)

Thanks in advance, I really do want to understand the WebSDK because this shows great potential!


In your console.log call, make sure that ControlID is,set. I suspect that it’s not being passed through. Since the ControlID is the DOM I’d of the outermost tag of your control (or at least it should be), you can probably get it from

You may also want to use our AddListener method instead because it supports older IE browsers that don’t support addEventListener.

I’m getting some weird ID’s indeed that I’m going to check out, but that could be possibe as my webcontrol creates a series of layered canvases itself. Probably using the wrong one. Using does give it back on one of them, not the others.

But my mistake was I used ‘mousedown’ as the name of my event. That was why it triggered Xojo, but stopped in pause mode until I clicked play again. Changing it to ‘mymousedown’ in

Xojo.triggerServerEvent(, 'mymousedown', [x,y]);"

did trigger the ExectureEvent. Going to have to be very careful with my namings.

On a side note: Just tested in Safari on mac also (thought it may be a Windows thing) and I noticed something other. Canvases cannot be layered in Safari: they appear next to each other! Pity, speedwise for the engine, but I’m going to have to find something different and that may solve the ControlID problem too.

Thanks for your time on a saturday :slight_smile:

The controlID was wrong indeed. Copy & paste a couple of hours ago from the webcontrol class to the webcontrol on the webpage: result => self.controlID is something completely different, in that case being the webpage1.ControlID instead of the WebControl.ControlID. Please remove the posibility to copy & paste in the IDE :wink:

So now I it works perfectly passing all the mousedowns on every canvas to the Xojo webcontrol.

  s.Append "XojoCustom.alwaysbusy.abwebcanvas.activatemousedown = function activatemousedown() {"
  s.Append "    Xojo.addListener(controlID,'mousedown', function(event) {"
  s.Append "        var x = event.pageX;"
  s.Append "        var y = event.pageY;"
  s.Append "        Xojo.triggerServerEvent(controlID, 'domousedown', [x,y]);"
  s.Append "    });"
  s.Append "};"

Very happy and tired :slight_smile: