call a plugin method (function) from the xm

  • Hello,

    I would like from a hotspot call a function in a plugin, and I doesn't work...
    For example, I have in my xml :

    <hotspot .... onclick="myAction(param)"> ... </hotspot>

    and then an action calling my plugin :

    <action name="myAction">
    plugin[nameOfMyPlugin].executeAFunction(%1);
    </action>

    The trace panel shows "unknown action command: plugin[main]. executeAFunction"

    In my plugin class, my function is public.
    Is there something else I should do ?

    Thanks for the help.

  • Hi,

    In my plugin class, my function is public.
    Is there something else I should do ?

    you need to make your function also public/available to krpano,
    e.g.
    to add your function to krpano's 'global' scope do just this:

    as3:

    Code
    function yourfunction(parameter)
    {
      ...
    }
    
    
    ...
    krpano.set("yourfunction", yourfunction);
    ...

    xml:

    Code
    ... onclick="yourfunction(hello);" ...


    or add the function direct to your plugin[]:

    as3:

    Code
    set("plugin[nameOfMyPlugin].executeafunction", executeAFunction);


    or:

    Code
    var pluginobject = krpano.get("plugin[nameOfMyPlugin]");
    pluginobject.executeafunction = executeAFunction;

    xml:

    Code
    plugin[nameOfMyPlugin].executeAFunction(%1);

    note - when direct adding functions to the plugin object (pluginobject.executeafunction = ...)
    they must be lowercase to be callable from krpano xml!

    best regards,
    Klaus

  • I have a very similar problem. I am trying to call a plugin function from xml:

    <plugin name="filesave" url="plugins/filesave.swf" />

    <action name="savetext_icon_clicked">
    plugin[filesave].savefile;
    </action>

    private function registerPlugin(event:DataEvent) : void {
    this.plugin_object = this.krpano.get(event.data);
    this.plugin_object.registerattribute("addText", "");
    this.plugin_object.registerattribute("clearText", "");

    this.plugin_object.savefile = savefilefunction;
    return;
    }

    public function savefilefunction():void
    {
    fileRef = new FileReference();
    fileRef.save(str, "NewFile2.txt");
    }

    I am getting unknown action: plugin[filesave].savefile; *sad*

  • Hi,

    either add - preload="true" - to your plugin - or use the "onloaded" event to make sure that the plugin is already loaded so your added function already there,

    if your are loading other pano/scene then also add - keep="true" - to avoid that your plugin will be removed,

    best regards,
    Klaus

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!