• Hi,

    I'm trying to use the new "loadjs" feature.

    This is my javascript:

    Code
    function functionToCall(var1) {
    	console.log("functionToCall called with " + var1);
    	return var1*2;
    }

    When I put the above code inside <script></script> in the main .html, I can use

    Code
    jsget(result, functionToCall(2));
    trace(get(result));

    I get the expected "4" in the console.

    Now I want to use that same function, but inside a .js loaded through loadjs().

    I tried various calls, but all return
    jsget - ReferenceError: functionToCall is not defined
    WARNING: Unknown action: functiontocall

    For example with these statements:

    Code
    loadjs("testjs.js", jsget(result, functionToCall(2)));
    loadjs("testjs.js", functionToCall(2));

    The script itself loads fine, if I put a console.log() outside the function, the message is shown in the js console. Also, if I put functionToCall(2) outside the function, the function is executed. But I just cant access the functions in the script from with the krpano actions.

    Anything I missed?

  • Hi,

    the Javascript code runs within its own context, separated from all others to avoid any interference.

    To make your function callable, it would need to be added somewhere.
    E.g. to the global 'window' object or the 'krpano' object (or anywhere else that allow access to it).

    Using just:

    Code
    function myfunction (...){ ... }

    defines a 'local' function and so is only available inside your js file.

    To export it, you could use to the global 'window' object:

    Code
    window.myfunction = function(...){ ... }

    Then it would be callable by jsget/jscall.

    Or add it to the 'krpano' or 'krpano.actions' objects:

    Code
    krpano.myfunction = function(...){ ... }
    OR:
    krpano.actions.myfunction = function(...){ ... }

    In these case, the function would be callable as krpano actions.

    or add your function to the krpano.inlinefunctions object:

    Code
    krpano.inlinefunctions.myfunction = function(...){ return ...; }


    Then it would be callable inside expressions.

    Best regards,
    Klaus

Participate now!

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