You are not logged in.

Dear visitor, welcome to krpano.com Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Thursday, April 12th 2018, 10:45pm

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?

2

Monday, April 16th 2018, 7:50pm

Sorry, but I don't understand what you mean... What kind of events?

3

Wednesday, April 18th 2018, 7:55pm

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).

4

Wednesday, April 18th 2018, 9:29pm

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

JS:

Source code

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


XML:

Source code

1
events.dispatch("my_custom_event_when_something_is_done");

5

Thursday, April 26th 2018, 2:52pm

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:

Source code

1
2
3
4
5
6
7
8
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 !