Skip to main content
Inspiring
March 4, 2016
Answered

gotoAndStop not working for dynamic text scoring

  • March 4, 2016
  • 1 reply
  • 277 views

gotoAndStop for score not working . when my score is 30 it should go to frame 5

stop();

var score:Number=0;

movieClip_1.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler_2);

function fl_MouseOverHandler_2(event:MouseEvent):void

{

  score=score+10;

  text1.text=String(score);

}

if(score==30) {

  gotoAndStop(5);

}

This topic has been closed for replies.
Correct answer Ned Murphy

The code as you show it will only execute once, immediately upon entering that frame - it does not monitor for a change in value.   Unless you are continuously returning to that frame so that the code executes repeatedly, it is only going to execute that if() code once while you are in the frame.  If the score is not 30 when you are entering that frame then it will not go to frame 5.

Move it inside the function where it will execute every time the score changes and see if it does what you want...

function fl_MouseOverHandler_2(event:MouseEvent):void

{

  score=score+10;

  text1.text=String(score);

  if(score==30) {

     gotoAndStop(5);

  }

}

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
March 4, 2016

The code as you show it will only execute once, immediately upon entering that frame - it does not monitor for a change in value.   Unless you are continuously returning to that frame so that the code executes repeatedly, it is only going to execute that if() code once while you are in the frame.  If the score is not 30 when you are entering that frame then it will not go to frame 5.

Move it inside the function where it will execute every time the score changes and see if it does what you want...

function fl_MouseOverHandler_2(event:MouseEvent):void

{

  score=score+10;

  text1.text=String(score);

  if(score==30) {

     gotoAndStop(5);

  }

}