Sie sind nicht angemeldet.

Lieber Besucher, herzlich willkommen bei: krpano.com Forum. Falls dies Ihr erster Besuch auf dieser Seite ist, lesen Sie sich bitte die Hilfe durch. Dort wird Ihnen die Bedienung dieser Seite näher erläutert. Darüber hinaus sollten Sie sich registrieren, um alle Funktionen dieser Seite nutzen zu können. Benutzen Sie das Registrierungsformular, um sich zu registrieren oder informieren Sie sich ausführlich über den Registrierungsvorgang. Falls Sie sich bereits zu einem früheren Zeitpunkt registriert haben, können Sie sich hier anmelden.

1

Mittwoch, 10. November 2010, 21:15

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:

Quellcode

1
<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.

Quellcode

1
2
3
4
5
6
7
8
9
	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:

Quellcode

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

2

Freitag, 12. November 2010, 20:38

Passing a value works but...

Passing the image.frame value explicitly (value is 36 in this example) in the loadobject() call initiated from onlick works as it should:

Quellcode

1
<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:

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var swf = createswf("viewer.swf", "viewerSWFObject", "100%", "500", "#FFFFFF");
	swf.addVariable("xml", "01.xml");
	swf.embed("viewerDIV");
	
	
	
	function viewer() 
	{
		return document.getElementById("viewerSWFObject");
	}
	
	function getframe()
		{
			var frame = viewer().get("image.frame") ;
			
			document.getElementById("frameplace").innerHTML = frame;  
			
		}
	
	
	function loadobject(xmlname,myframe)
	{
		viewer().call("loadpano(" + xmlname + ", image.frame=" + myframe +" , MERGE, BLEND(1));");
	}
	



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:

Quellcode

1
2
3
4
5
6
<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:


Quellcode

1
2
3
4
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!

3

Freitag, 12. November 2010, 22:05

Hi Macio,

In my opinion your code is correct...

Can you post a link to see what is going wrong?

SAlut.

4

Montag, 22. November 2010, 20:10

Hi Michel,

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

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
	var swf = createswf("viewer.swf", "viewerSWFObject", "100%", "500", "#FFFFFF");
	swf.addVariable("xml", "01.xml");
	swf.embed("viewerDIV");
	
	
	
	function viewer() 
	{
		return document.getElementById("viewerSWFObject");
	}
	
	
	function loadobject(xmlname,myframe)
	{
		var myframe = viewer().get("image.frame"); 
		viewer().call("loadpano(" + xmlname + ", image.frame=" + myframe +" , MERGE, BLEND(1));");
	}


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):

Quellcode

1
2
3
4
5
6
		<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:

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
<plugin name="object_01"
		url="preview/08.png"
		scale="1"
		edge="center"	
		align="lefttop"
		x="75"
		y="60"
		onclick="action(my_load_pano,08.xml)"
		onhover=""
		onover=""
		onout =""	
		/>



The following also does NOT work:

Quellcode

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



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

Quellcode

1
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.

5

Dienstag, 23. November 2010, 00:00

Hi Macio,

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

Quellcode

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


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

Quellcode

1
2
3
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.

6

Dienstag, 23. November 2010, 04:02

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*