Javascript variable into loadpano call

  • I'm trying to pass the current frame into a loadpano call within Javascript and am not sure what I am doing wrong. My guess is my syntax. Any suggestions?

    Thanks!

    This is the trigger:

    Code
    <td><center><img src="preview/10.png" width="65" height="65" onclick="getframe();loadobject('10.xml');" /><br>10.xml</center></td>

    This is the function that get's the current frame number (which I have tested by getting a value in a HTML text field.

    Code
    function getframe()
    		{
    			var frame = Number( viewer().get("image.frame") );
    			
    			document.getElementById("frame").innerHTML = frame;
    			
    		}

    This does not work, meaning the image.frame parameter is not feeding my Javascript frame variable from the getframe() function:

    Code
    function loadobject(xmlname)
    	{
    		viewer().call("loadpano(" + xmlname + ", image.frame=frame , MERGE, BLEND(1));");
    	}
  • Passing the image.frame value explicitly (value is 36 in this example) in the loadobject() call initiated from onlick works as it should:

    Code
    <td><center><img src="preview/08.png" width="65" height="65" onclick="getframe();loadobject('08.xml',36);" /><br>08.xml</center></td>

    This is the embed code I used and the getframe() and loadobject() functions:


    But trying to pass the javascript frame variable into the loadpano call fails. I can get the current image frame number using the getframe() function, but there is something odd about passing this to the loadpano call.

    I also tried this with no luck:

    Code
    <td><center><img src="preview/08.png" width="65" height="65" onclick="getframe();loadobject('08.xml',frame);" /><br>08.xml</center></td>
    
    
    function loadobject(xmlname,myframe)
    	{
    		viewer().call("loadpano(" + xmlname + ", image.frame=" + myframe +" , MERGE, BLEND(1));");
    	}

    and this:


    Code
    function loadobject(xmlname,frame)
    	{
    		viewer().call("loadpano(" + xmlname + ", image.frame=" + frame +" , MERGE, BLEND(1));");
    	}

    Does a loadpano call need to be constructed before it is called - and if so how come passing an explicit variable works but trying to pass something stored in Javascript does not?

    I'm going crazy here!

  • Hi Michel,

    I finally figured this out. It was a scoping issue. This works (look at the loadobject function):

    The variable myframe has to be declared inside the loadobject function in order for it to be available to the loadpano call. I suppose it could have also been declared outside the loadobject function, but it has to be done explicitly using the var statement.


    I am now having a problem replicating this using xml code. The following DOES NOT work (but I am getting results from both trace(myframe) commands in debug mode):

    Code
    <action name="my_load_pano">
    			set(myframe,get(image.frame));
    			trace(myframe);
    			loadpano(%1,image.frame=myframe,KEEPALL,BLEND(0.5));wait(blend);
    			trace(myframe);
    		</action>

    This triggers the above:


    The following also does NOT work:

    Code
    loadpano(08.xml,image.frame=get(image.frame),KEEPALL,BLEND(0.5));wait(blend);


    This on the other hand works (as it should):

    Code
    loadpano(08.xml,image.frame=36,KEEPALL,BLEND(0.5));wait(blend);

    I am starting to suspect that there is something specific about the way the loadpano() call or function gets assembled and the way in which it accepts variables.

  • Hi Macio,

    I thing you can not use a get() action inside the vars parameter of the loadpano() action...
    So, instead of:

    Code
    loadpano(08.xml,image.frame=get(image.frame),KEEPALL,BLEND(0.5));wait(blend);

    try to construct the loadpano() using a txtadd():

    Code
    txtadd(temp,'loadpano(08.xml,image.frame=',get(image.frame),',KEEPALL,BLEND(0.5))');
    call(temp); <!-- this line calls the constructed loadpano() -->
    wait(blend);

    Hope this help *smile* ...

    SAlut.

  • Thanks Michel !

    I was starting to think I would have to construct the call as text first (just like your example) and the execute it. Your code works perfectly!


    However I think that there also must be a way of passing a variable rather than a fixed value into the vars of loadpano().


    Thank you again *cool*

Participate now!

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