else statement always run even the answer is true

104 Views Asked by At

tnx! it works. but when i tried to add another object named, p1_2 and add the "trace" thing to the code, it goes back to the same problem.

p1_1.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void
{
    question.text = "shape?";
}
submit.addEventListener(MouseEvent.CLICK, onClickss);
function onClickss(e:MouseEvent):void
{

    trace("ans.text = "+ans.text); 
    if (ans.text == "circle")
{
    p1_1.visible = false;
}
else
{
    gotoAndStop(6);
}

}




p1_2.addEventListener(MouseEvent.CLICK, onClick2);
function onClick2(e:MouseEvent):void
{
    question.text = "Color?";
}
submit.addEventListener(MouseEvent.CLICK, onClickss2);
function onClickss2(e:MouseEvent):void
{
trace("ans.text = "+ans.text);
if (ans.text == "red")
{
    p1_2.visible = false;
}
else
{
    gotoAndStop(6);
}

}

what should i do.? do i nid to seperate p1_2 in another frame and make another inputtextfield for it? im planning to add 5 objects on the stage. until p1_5. -_-

1

There are 1 best solutions below

5
On

Before the line...

if(ans.text == "circle") {

...add:

trace("ans.text = "+ans.text); 

Clicking the submit button will trace the actual value of ans.text to the output panel when you test your movie in Flash. If you get a null reference error then ans has not been instantiated. Otherwise, knowing the actual value of ans.text should point you in the right direction to solve the problem.