Var counter thingy - easy peasy (no really)

I have a SWF that loops on the main.

now I want that after 4 or 5 times of looping it does an action.

I know that with Var I can count and then with a little action I can instruct Flash that when a var value is reached it executes an action.

But how again do I do that?

(it was something with varofsumthing = β€œ+1”

if varofsumnthing == β€œ5”
gotoandplay(whatever)

hope you lot can help me out :slight_smile:


if(counterVariable++ == 5){
  //  Do something.
}

Just make sure you initialize counterVariable first. :slight_smile:

-Al

so my varofsumthing = β€œ+1” was actually correct???

wow! :wink:

in one frame I have this to either continue to play if the varcount did not reach 3 or to stop if it did…

if (this.countvar++ == 3) {
this.gotoAndStop(347);
}
else { 
this.gotoAndPlay(347);
}

and this action to set the var with each loop with an increase of 1

this.countvar +=1;

but, as you guessed… It don’t work :slight_smile:

variable++ is the same as variable += 1

So in my code, the variable is incremented in the IF statement.

Now that I have a better idea of what you want, try this in frame 347:


if (this.countvar == 3) {
  this.stop();
} else { 
  this.gotoAndPlay(346);
}

You have to go to the previous frame. Going to the same frame won’t work (I think). And of course, make sure you have this in a frame before 346:


this.countvar = 0;

And you need to increment your counter somewhere with your


this.countvar += 1;

or


this.countvar++;

-Al

works fine!

thanks mate!