2 Replies Latest reply on Mar 9, 2012 2:16 PM by Reincke1515

    Buttons navigation

    Reincke1515

      I'm just getting started using Flash Builder and need some help. Is there a way for me to make a button that will send a user to a different screen randomly. I'm a teacher and trying to create a math app for my students, where after there answer a question correctly, it sends them to the next question at random. Here is the code I have thus far, but it will only send them to the next question. Thanks for any help!

       

      <s:Button x="324" y="273" label="Next Question"

                    click="navigator.pushView(question2)" styleName="back" />

        • 1. Re: Buttons navigation
          RileyPaulsen

          Turn the click handler into a full on separate function. Then store all the views in an array and use Math.rand() to randomly choose one.

           

          Something like this:

           

          <fx:Script>

               <![CDATA[

                    var questionsArray:Array = {question2,question3,question5,questionRed,questionGeography};

           

                    function buttonClickHandler(event:MouseEvent){

                         var randomProblem:int = Math.floor(Math.random()*(questionsArray.length));     //generates a random integer between 0 and the total number of questions in the array (arrays are 0-based)

                         navigator.pushView(questionsArray[randomProblem]);

                    }

               ]]>

          </fx:Script>

           

          <s:Button id="randomProblemButton" label="Next Problem" click="buttonClickHandler(event)" />

           

          Haven't tested that, but something along that line should work

          1 person found this helpful
          • 2. Re: Buttons navigation
            Reincke1515 Level 1

            Thanks for the response. Couldn't seem to get it to work, but I will keep playing around with it.