Reputation: 28
private function BatCondition():void
{
//updateScoreText();
if (nScore == 10)
{
trace('run once')
}
}
okay. so you see when the score is 10. it keeps tracing one once, x amount of times when i want it to run once, help.
p.s break does not work. C:\Users\Admin\Desktop\update2\src\Main.as(337): col: 22 Error: Target of break statement was not found.
Upvotes: 0
Views: 1593
Reputation: 3141
Here's a way how break out of an if statement.
mainIf: if (some_condition)
{
trace("Main condition")
innerIf: if (your_condition)
{
trace("inner if");
break mainIf;
}
trace("this won't work")
}
If you want to break out of an if statement or a loop use the break
keyword. If you have multiple if's and or loops you can add labels to them to target the if/loop you want to break out of.
Upvotes: 3
Reputation: 3292
How about a class level var to act as a flag.
eg,
private var score_at_ten_flag:Boolean = false;
private function BatCondition():void {
if (nScore == 10 && !score_at_ten_flag) {
score_at_ten_flag = true;
trace('run once');
}
}
Upvotes: 1
Reputation: 379
private function BatCondition():void {
//updateScoreText();
if (nScore == 10)
{
trace('run once')
break;
}
}
Upvotes: 1