Linking to random scenes using Javascript

Hi,

The real problem is you are not understanding the code.
In the code you had, you were trying to have the button's parent set it's location to an URL. But what you put in was a Hype Javascript command to change scenes. Not an URL.

What you should be doing is just put the scene names in the array and randomly use the Hype Javascript in the correct way to change the scene.

   var links = ["scene1","scene2","scene3"];


    function untitledFunction() {
      // Chooses a random link:
      var i = Math.floor(Math.random() * links.length);
      // Directs the browser to the chosen target:
      hypeDocument.showSceneNamed(links[i], hypeDocument.kSceneTransitionCrossfade, 1.1);
      return false;

    }	
      untitledFunction();	

I also suggest you have a look at this learning resource.. :smile:

3 Likes