• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Buttons navigation

New Here ,
Feb 27, 2012 Feb 27, 2012

Copy link to clipboard

Copied

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" />

Views

479

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 08, 2012 Mar 08, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 09, 2012 Mar 09, 2012

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines