Listen to to KRpano events inside the plugin (SOLVED)

  • Is there a way to listen to onnewpano event (or any other KRpano event available in XML) inside plugin (both Flash and JS)?
    Or the only way is to add function to plugin and call it from XML when event fires ?

    By now I use a workaround which works but doesn't look very nice.
    AS3 code:

    Code
    var prevOnNewPano:Function = krpano.get("events.onnewpano");
    krpano.set("events.onnewpano", function(){(prevOnNewPano!=null)?prevOnNewPano():null; onNewPano();});
    
    
    private function onNewPano(...rest):void {
       .......
    }


    It creates new function which takes current onnewpano function and adds onNewPano call to it.

    I also noticed that onnewpano event doesn't fire if image type is QTVR!

  • Hi,

    you can use named events to avoid overwriting the global ones,

    e.g. in the registerplugin function add the events by doing:

    Code
    krpano.set("events[myevents].onnewpano", ...);
    krpano.set("events[myevents].keep", true);

    or

    Code
    var myevents:* = krpano.events.createItem("myevents");
    myevents.onnewpano = ...;
    myevents.keep = true;

    and in the unloadplugin function remove it by:

    Code
    krpano.set("events[myevents].name", null);

    or

    Code
    krpano.events.removeItem("myevents");

    and instead of "myevents" you could use a dynamically generated unique name to avoid interferes,
    e.g. the plugin name + "_events" or and an random/time-based number,

    btw - the createItem and removeItem krpano array functions were documented here:
    https://krpano.com/docu/plugininterface/#array.removeItem

    I also noticed that onnewpano event doesn't fire if image type is QTVR!

    okay, I will check this,

    best regards,
    Klaus

Participate now!

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