Confusing screentosphere... and delayed call?

  • Hi,

    I'm getting different results on the javascript version compared to the flash version of krpano.

    This is called from javascript:

    Works on Flash, not on KrpanoJS, Note: I put values in there, not variables:

    Code
    var mousex = krpano.get("mouse.x");
    var mousey = krpano.get("mouse.y");
    var spherical_coordinates = krpano.get("screentosphere("+mousex+","+mousey+")"); //convert x/y in ath/atv
    var coordinates_array = spherical_coordinates.split(",");

    According to the docs, you need to put variables in there, not values. But since I got an array returned, I though I dont have to provide the other 2 parameters (the variables krpano will set)
    So I put variables in there:

    Code
    var spherical_coordinates = krpano.get("screentosphere(mouse.x, mouse.y)"); //convert x/y in ath/atv
     var coordinates_array = spherical_coordinates.split(",");


    But I get a ["NaN", "NaN"] in flash, and a null on KrpanoJS

    This works on both, but the variables arent available yet after the call..

    Code
    krpano.call("screentosphere(mouse.x, mouse.y, sphere_horizontal, sphere_vertical)"); //convert x/y in ath/atv
    var _ath = krpano.get('sphere_horizontal');
    var _atv = krpano.get('sphere_vertical');


    first I though because screentosphere needs some time to calculate. But doing a

    Code
    krpano.cal('set(test, 10)'); 
    krpano.get('test'); //returns null


    I get the same problem. The variable isnt available right after the call, but doing the same get command in the terminal gives me the 10.

    Code
    krpano.set('test', 10);
    krpano.get('test'); //return 10

    Directly setting works though. But since I have to use a call for the screentosphere, I can't use a get :(

    So my question, what is the right way, that works on both KrpanoJS and SWF, so that given an x/y coordinate, returns the ath/atv immedietly.

    other question, but not important, why does screentosphere expect different values in different context?

    Update:

    Ok stranger results:

    Code
    krpano.call("screentosphere(mouse.x, mouse.y, sphere_horizontal, sphere_vertical); showlog(); trace(sphere_horizontal)"); //convert x/y in ath/atv
    var _ath = krpano.get('sphere_horizontal');
    var _atv = krpano.get('sphere_vertical');
    krpano.call('trace(js: '+_ath+')');

    Tracelog:

    Code
    INFO: -72.42665479744863
    INFO: js: null

    the trace that gets called later, doesnt have the same value...

    Edited once, last by Zephyr (March 15, 2012 at 11:28 AM).

  • Hi

    I still haven't found a good solution for this, other then a timeout...

    Anyone knows a more reliable way?

  • Hi,

    the problem is that the actions that were passed by 'call' to krpano weren't always executed immediately - will be added to an 'queue' of actions and this queue will be executed step by step. And some krpano actions like the lookto, wait and loadpano actions are pausing this 'action queue' during they are processing.

    That means the Flash AS3 and the krpano XML actions are not automatically synced.

    A solution would be a 'async' callback from xml to AS3 when the screentosphere action is done.

    e.g.

    best regards,
    Klaus

  • this could help but I'm using javascript and use a modular object/class setup. So my call would be something like:

    Code
    krpano.call("screentosphere(mouse.x, mouse.y, sphere_horizontal, sphere_vertical); js(Tour.Hotspotview.move());");

    And I remember that there was some issues in nested object functions like this. So I would need to register some function to the window object

    Code
    krpano.call("screentosphere(mouse.x, mouse.y, sphere_horizontal, sphere_vertical); js(screentospherecallback());");
    
    
    window.screentoscpherecallback = function(){
       Tour.Hotspotview.move();
    }

    It's a kind of coupling I dont really prefer. Perhaps I could loosely couple it with an event instead of function callback... hmm

    Would this suggestion alsoo work in javascript or is js() the only way to do an javascript call?

    Code
    var callback = function(){
       //handle it
    }
    krpano.set("mycallback", callback);
    krpano.call("screentosphere(mouse.x, mouse.y, sphere_horizontal, sphere_vertical); mycallback();");
  • Hi,

    Would this suggestion alsoo work in javascript or is js() the only way to do an javascript call?

    yes, this code should work in js too,
    it's possible to add js Functions to krpano variables and then call them from xml (but only in the HTML5 viewer, in the Flash Viewer, AS3 need to be used for that of course)

    best regards,
    Klaus

Participate now!

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