how to call a Javascript plugin method from outside?

  • I have a Javascript plugin for the HTML5 viewer. I need to call its methods from outside krpano. What's the right way to do it?
    In my plugin I do:

    Code
    local.registerplugin = function (krpanointerface, pluginpath, pluginobject) {
    plugin.attachEvents = attachEvents;
    }
    function attachEvents() {alert('attached');}


    then I've tried calling:

    Code
    krpano.call("attachEvents();");

    and

    Code
    krpano.call("plugin[myplugin]attachEvents");


    but notghin happens.

  • Hi,

    here you need to use 'pluginobject' to access the krpano plugin object - and the name of the function at the plugin object need to lowercase (!):

    and here a dot (.) and brackets are missing:

    Quote

    krpano.call("plugin[myplugin].attachEvents()");


    Best regards,
    Klaus

  • My fault, I meant pluginobject in my first code snippet.
    Calling with

    Code
    krpano.call("plugin[myplugin].attachEvents()");




    didn't work wither.
    I've completely rearranged my plugin. Now I instantiate it by myself, passing the krpano object to it . Far more flexible and easy to manage ;)
    Thanks anyway.

  • Make sure the function name was written here in lower case:
    pluginobject.attachevents = attachEvents;

    To provide case-insensitive access, krpano internally converts all actions to lower case, so the function name also need to be lower case to be call-able by krpano.

    Best regards,
    Klaus

  • Thanks for the help, but it doesn't work with lower case neither.
    Should I define some more parameter when I define the plugin?

    Code
    <plugin name="myplugin"	url="myplugin.js"  parent=""	preload="true"	x="0" y="0"	visible="true"	keep="true"/>

    I use the krpano obtained from "krpanoSWFObject"

    Code
    krpano = document.getElementById('krpanoSWFObject');krpano.call("plugin[myplugin].attachevents()");


    PS: does the HTML5 viewer use SWF under the cover?

Participate now!

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