You are not logged in.

1

Wednesday, November 10th 2010, 9:15pm

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:

Source code

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.

Source code

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:

Source code

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

2

Friday, November 12th 2010, 8:38pm

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:

Source code

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:

Source code

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:

Source code

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:


Source code

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!

michel

Professional

Posts: 1,153

Location: ANDORRA

Occupation: TV

  • Send private message

3

Friday, November 12th 2010, 10:05pm

Hi Macio,

In my opinion your code is correct...

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

SAlut.

4

Monday, November 22nd 2010, 8:10pm

Hi Michel,

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

Source code

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

Source code

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:

Source code

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:

Source code

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



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

Source code

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.

michel

Professional

Posts: 1,153

Location: ANDORRA

Occupation: TV

  • Send private message

5

Tuesday, November 23rd 2010, 12:00am

Hi Macio,

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

Source code

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


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

Source code

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

Tuesday, November 23rd 2010, 4:02am

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*