A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: How to add betting to a quiz?

  1. #1
    Junior Member
    Join Date
    Sep 2006
    Posts
    29

    How to add betting to a quiz?

    I have modified a multichoice quiz I use in school and would like to add an element whereby the user places a bet before answering. He starts with 200 points and inputs the proportion of this he would like to bet before pressing True or False. If he is right, the amount bet is added to the 200 and if he’s wrong, the amount is taken away, and so on.
    The relevant bit of script is this, but I’ve no idea how to change the ‘var pointsToEarn’ element to accept a number from the betting input.

    System.useCodePage = true;
    var randomNum;
    var pointsToEarn = 1;
    var pointsToLose = 1;
    a = new String(null);
    b = new String(null);
    c = new String(null);
    d = new String(null);
    var numOfQuestions;
    question = new String(null);
    var spotA;
    var spotB;
    var spotC;
    var spotD;
    var score = 200;
    var index = 0;
    if (list == undefined) {
    list = new LoadVars();
    list.load("questions.txt");
    }
    gotoAndPlay(2);



    Here's the Fla http://www.proenglish.es/betting_quiz.zip (I wasn't able to attach)

    Thanks in advance for any help. I had some great help last time and the result is still being enjoyed by my colleagues in school.

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    106
    You will need to do 3 things:

    1) create a variable for your input text
    2) write a function to set your variable
    3) call the function when you click on the buttons.

    1) to create the variable, you will need to select the input text box, and assign a name to a variable. I used betAmount in my sample.

    2) You will need to write a function to set your input text. You notice that I wrapped the betAmount in a Number() so that flash will see the betAmount as a number and not a String.
    function setPoints(){
    //trace(betAmount)
    pointsToEarn=Number(betAmount);
    pointsToLose=Number(betAmount);
    }

    3) on the answer buttons, you will just need to call the function setPoints();

    n (release) {
    setPoints();
    //trace(pointsToEarn);
    var timeStop = tenSeconds.sec;
    tenSeconds.gotoAndStop(5);
    tenSeconds.stopText.text = timeStop;
    tenSeconds.timer = clearInterval(tenSeconds.timer);
    if(spotA == -1)
    {
    score += pointsToEarn;
    gotoAndStop("Correct");
    }
    else
    {
    score -= pointsToLose;
    gotoAndStop("Incorrect");
    }
    }

    This makes the score part work, but I noticed you need to turn off visibility of the betAmount

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center