I am making a quiz game where the question is displayed according to a variable. Each question is displayed in a dynamic text box and set within an if statement however after the question variable changes the question text doesn’t change unless the movie is closed and then reopened. I am not sure if I am doing something wrong or the stage need to be updated to show the changes.
The user has two buttons to click which will correspond to an answer one is right and the other is wrong. The correct answer will increment the score and the level and the incorrect answer will only increment the level. however the if statement for the level variable is not showing the updated content however tracing the variable shows that is being incremented.
import flash.events.MouseEvent;
score_txt.text = "Score:" + so.data.score;
level_txt.text = "Level:" + so.data.levels;
if (so.data.levels== 1)
{
so.data.levels = 1;
so.data.score = 0;
question_txt.text = "Question 1:";
a_btn.addEventListener(MouseEvent.CLICK, a1);
b_btn.addEventListener(MouseEvent.CLICK, b1);
function a1(e:MouseEvent):void
{
updateScore();
nextLevel();
updateTextFields();
}
function b1(e:MouseEvent):void
{
nextLevel();
updateTextFields();
}
}
if (so.data.levels == 2)
{
question_txt.text = "Question 2:";
a_btn.addEventListener(MouseEvent.CLICK, a2);
b_btn.addEventListener(MouseEvent.CLICK, b2);
function a2(e:MouseEvent):void
{
nextLevel();
updateTextFields();
}
function b2(e:MouseEvent):void
{
updateScore();
nextLevel();
updateTextFields();
}
}
function nextLevel():void
{
so.data.levels++;
}
function updateScore():void
{
so.data.score++;
}
function updateTextFields():void
{
score_txt.text = "Score:" + so.data.score;
level_txt.text = "level:" + so.data.levels;
}