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:


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

    Code
    function zufallsZahl () { 
    var ran_number = Math.floor(Math.random()*5); 
    alert(ran_number); 
    return ran_number; 
    }


    XML

    Code
    <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?

  • Hi malojo,

    I have played a little with that *wink* ...
    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 :

    Zitat

    The krpano object exports this 3 functions to javascript:

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


    Your scripts.js would be:

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

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

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!