You are not logged in.

1

Thursday, November 12th 2009, 12:45pm

Get Random numbers?

Hi,

is there a way that I can get random values back into my pano?

I have a java script function with generates the numbers. But how to I get them back into my xml?

HTML:



Source code

1
2
3
4
5
<script type="text/javascript" src="scripts.js"></script> 
<object width="640" height="480"> 
<embed src="panomax.swf" width="640" height="480" allowFullScreen="true"> 
</embed> 
</object>



JS:

Source code

1
2
3
4
5
function zufallsZahl () { 
var ran_number = Math.floor(Math.random()*5); 
alert(ran_number); 
return ran_number; 
}




XML

Source code

1
2
3
4
5
 <action name="loadrandom"> 
trace(myvar.vari); 
set(myvar.vari, js(zufallsZahl())) ; 
trace(myvar.vari); 
</action>




myvar.vari does exist.

Regardless if I use the get before js or the js itself. I do not get the result back to my variable.

If I do just js(zufallsZahl()); the function is called as wished.

Can this be done?

michel

Professional

Posts: 1,153

Location: ANDORRA

Occupation: TV

  • Send private message

2

Thursday, November 12th 2009, 3:05pm

Hi malojo,

I have played a little with that ;-) ...
First, I noticed that your loadrandom() action does not execute the call to your JavaScript function zufallsZahl()... The alert(ran_number); does not displays !!!
Second, (I am going to explain the way I understand, perhaps I am wrong and sure not the best explanation *g* ) I think, the way you embed your panomax.swf does not allow javascript to communicate with him... there is no element ID to communicate with... Also, I do not think that return ran_number; can be the way to communicate with Krpano... Look at the Javascript Interface Doc :

Quoted

The krpano object exports this 3 functions to javascript:

Source code

1
2
3
set(variable,value) ... sets the variable to the
get(variable) ... returns the value of the variable
call(action) ... calls a action

I think you have to use the method described in the doc Flash Embedding Javascript using SWFObject 1.5 / SWFObject 2.1 .
So, your html code would be something like this:

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<html>
<head>
	<title>krpano Javascript</title>
</head>
<style>
body{ font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#FFFFFF; background-color:#000000; margin:0; padding:0; }
* html, * html body{ overflow: hidden; }
a{ color:#AAAAAA; text-decoration:underline; }
a:hover{ color:#FFFFFF; text-decoration:underline; }
</style>
<body>

<div id="krpanoDIV">
	<noscript><table width="100%" height="100%"><tr valign="middle"><td><center>ERROR:<br/><br/>Javascript not activated<br/><b/r></center></td></tr></table></noscript>
</div>

<script type="text/javascript" src="swfobject/swfobject.js"></script>
<script type="text/javascript" src="swfobject/swfkrpanomousewheel.js"></script>

<script type="text/javascript" src="scripts.js"></script>

<script type="text/javascript">
// <![CDATA[
	if (typeof(deconcept) !== 'undefined')
	{
    	if (deconcept.SWFObjectUtil.getPlayerVersion().major >= 9)
    	{
        	var so = new SWFObject("panomax.swf","krpanoSWFObject","640","480","9.0.28","#000000");
        	so.addParam("allowFullScreen","true");

        	if (so.write("krpanoDIV")) { var mousewheelfixes = new SWFkrpanoMouseWheel(so); }
    	}
    	else
    	{
 	document.getElementById("krpanoDIV").innerHTML = '<table width="100%" height="100%"><tr valign="middle"><td><center>ERROR:<br><br>Adobe Flash Player 9 needed<br><br><br><a href="http://www.adobe.com/go/getflashplayer/" target="_blank"><IMG SRC="http://www.macromedia.com/images/shared/download_buttons/get_flash_player.gif" BORDER="1"></a><br>...click here to download...<br><br><br><br></center></td></tr></table>';
    	}
	}
	else
	{
 	document.getElementById("krpanoDIV").innerHTML = '<table width="100%" height="100%"><tr valign="middle"><td><center>ERROR:<br/><br/>swfobject.js not found<br/><br/></center></td></tr></table>';
	}
// ]]>
</script>

</body>
</html>

Your scripts.js would be:

Source code

1
2
3
4
5
6
7
8
9
function krpano() 	{
	return document.getElementById("krpanoSWFObject");
	}
   
function zufallsZahl() {
	var ran_number = Math.floor(Math.random()*5);
	alert(ran_number);
	krpano().set("myvar.vari",ran_number);
	}

And your xml loadrandom() action would be:

Source code

1
2
3
4
5
<action name="loadrandom">
	trace(myvar.vari);
	js(zufallsZahl());
	delayedcall(0.5,trace(myvar.vari));
</action>

note: I have delayed the second trace(myvar.vari) because it seems that there is some delay before the Javascript function zufallsZahl() is fully executed !!!

Hope this can help...

SAlut.

3

Thursday, November 12th 2009, 4:22pm

Thanks,

I owe you a beer for helping me.

It works!!! *g* *g* *g* *g* *g*

This post has been edited 1 times, last edit by "malojo" (Nov 12th 2009, 4:39pm)


michel

Professional

Posts: 1,153

Location: ANDORRA

Occupation: TV

  • Send private message

4

Thursday, November 12th 2009, 5:27pm

Hi malojo,

Great, a beer *smile* . Cheers (salut i for├ža al canut *g* ). What about "Malojo" ? Are you spanish ?

SAlut.

5

Thursday, November 12th 2009, 9:12pm

No, english :D