A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Need help with Question codes

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    4

    Need help with Question codes

    Hi all,

    In a current game I am working on I've encountered the problem of questions stacked ontop of each other. By this I mean, I have an array of questions that go onto buttons 1 question at a time. The problem is that for every question I answer, it also answers the questions previous to it at the same time (Thus messing up my score)... Does anyone have any advice on how to fix the code below so that it won't happen?

    function Hitwat5(event:Event)
    {
    if (Person.hitTestObject(Watcoin5))
    {

    yScroll = 0;
    qBack5.visible = true;
    (qBack5);
    Watcoin5.y -= 1200;
    var buttons:Array = [qBack5.button15,qBack5.button25];

    var questions:Array = [];
    questions.push(["What is 40 divided by 5?", 1, "10", "8"]);
    //Medium;
    questions.push(["How many sides are there in a Pentagon?", 0, "5", "6"]);
    questions.push(["What has the same value as 3x4?", 1, "5x2", "6x2"]);
    questions.push(["What is missing? 17 + _ = 28?", 0, "11", "9"]);
    questions.push(["How many sides are on a cube?", 0, "6", "4"]);
    questions.push(["What is 9x4?", 1, "32", "36"]);
    questions.push(["How much are 2 dimes + a 3 nickles worth?", 0, "35cents", "25cents"]);
    questions.push(["What is 350-60?", 1, "260", "290"]);
    questions.push(["What is missing? 2 _ 4", 1, "=", "<"]);
    questions.push(["What is 23.4+20.3?", 0, "43.7", "41.5"]);

    function init(questionNum:int)
    {
    currentQuestion5 = questionNum;
    var question:Array = questions[questionNum];
    qBack5.questionText5.text = question[0];
    var j:int = 2;
    correctAnswer5 = question[1];
    trace(correctAnswer5);
    for (var i:int = 0; i < buttons.length; i++)
    {
    buttons[i].addEventListener("click", onClick);
    buttons[i].answerText.text = question[i + 2];
    }
    }

    function onClick(event:Event)
    {
    var index:int = buttons.indexOf(event.target.parent);
    trace("buttonIndex = " + index +" Correct answer = " + correctAnswer5);
    if (index == correctAnswer5)
    {
    onCorrect();
    }
    else
    {
    onIncorrect();
    }
    }

    function onCorrect()
    {

    score += 5;
    trace("scoreCorrect "+ score);
    nextQuestion();
    }

    function onIncorrect()
    {
    score -= 5;
    trace("scoreINCorrect "+ score);
    nextQuestion();
    }

    function nextQuestion()
    {
    update();
    for (var i:int = 0; i < buttons.length; i++)
    {
    buttons[i].removeEventListener("click", onClick);
    qBack5.visible = false;
    yScroll = Defaulty;
    }


    if (currentQuestion5 >= questions.length - 1)
    {
    gotoAndStop("Menu","Menu");
    }
    else
    {
    currentQuestion5++;
    init(currentQuestion5);
    }
    }

    function update()
    {
    scoreText.text = String(score);
    }


    stop();
    init(0);
    }
    }


    Thanks alot,
    Flash noob.

  2. #2
    Junior Member
    Join Date
    Jun 2013
    Posts
    4
    Bump! I really need help! Has to be fixed by tonight. Any suggestions!?!?

  3. #3
    Junior Member
    Join Date
    Jun 2013
    Posts
    4
    Come on guys, I need help ASAP

  4. #4
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    923
    nah, I don't feel like.
    who is this? a word of friendly advice: FFS stop using AS2

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