Dispatching events from within XML to the webpage JS

  • Is it possible to call dispatch events to the webpage, from within the krpano xml file?

    I am looking to dispatch eg. en event on the krpano object (that has been provided from embedpano/onready), with custom data, from within the loaded xml data.

    The alternative currently working method, is to use js() within xml and use an event dispatcher proxy object on a global scope variable. This is not ideal, and gets complicated if an unknown number of krpano players are set.

    Is it possible to dispatch events directly on the krpano object from within the krpano xml file?

  • I would like to do something like:

    $(krpano).on("my-custom-event-when-something-is-done", function(event) {
    alert("something was done inside the krpano player !");
    });

    ...and inside the krpano xml, have something somewhere

    events.trigger("my-custom-event-when-something-is-done");

    ...and even better with custom data.

    In otherwords, I want to trigger a custom event inside the player, which will be received/listened to outside the krpano xml.

    This would be useful if a specific button/hotspot was clicked inside the krpano player, but there were multiple instances of the krpano player running (and hence you cant just use the js() function to invoke something in the global scope of the document).

  • Sorry, still not sure what you what to do, but here your example ported to real code:

    JS:

    Code
    krpano.set("events.my_custom_event_when_something_is_done", function()
    {
      alert("something was done inside the krpano player !");
    });

    XML:

    Code
    events.dispatch("my_custom_event_when_something_is_done");
  • Hello Klaus,

    This works and meets my intention, but only in Html5 mode ! Your alert is not displayed when using Flash.

    Also, it does not allow multiple listening functions, eg:

    Code
    krpano.set("events.my_custom_event_when_something_is_done", function()
    {
      alert("FIRST something was done inside the krpano player !");
    });
    krpano.set("events.my_custom_event_when_something_is_done", function()
    {
      alert("SECOND something was done inside the krpano player !");
    });

    ...only the SECOND alert will display (although adding multiple listening functions could be extended with some code).

    Also, I dont see how custom data could be passed during the event dispatch (although this could also be extended with some krpano.call() code during the event listening functions).

    But the flash limitation blocks the use of this feature? How to get this working in flash mode?

    Thank you !

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!