Copy link to clipboard
Copied
I am trying to create a loop using the below:
"loop" is a frame label 1 frame after the below on the main timeline.
Can someone find what is keeping this from working?
Thank you!
var i = 0;
i++;
if (i < 2) {
this.play("loop");
} else if (i > 2) {
this.stop();
}
Thank you for the tips @ClayUUID. You got me on the right track. After making the adjustments you suggested, the loop works as expected.
/*defined i=0 in first frame
placed this.gotoAndPlay("restart"); on last frame
placed "restart" label on first frame */
if (i < 3) {
i++;
} else if (i == 3) {
this.stop();
}
ClayUUID Nov 15, 2016 8:28 PM (in response to Tony Dilger)
ANSWER!
You initialize i to zero every time you enter the frame.
The variable i only exists in that frame.
The conditional logic doesn't acc
...Copy link to clipboard
Copied
You initialize i to zero every time you enter the frame.
The variable i only exists in that frame.
The conditional logic doesn't account for i being equal to 2.
There's no such function as .play().
There's no need to use a frame label when you're just advancing to the next frame.
Copy link to clipboard
Copied
I use this in my banner ads to loop the creative 2x:
if(!this.alreadyExecuted){
this.alreadyExecuted=true;
this.loopNum=1;
} else {
this.loopNum++;
if(this.loopNum==2){
this.stop();
}
}
Copy link to clipboard
Copied
I don't know why people are still using that ungainly code when a perfectly functional two-liner has been posted here many times:
if (!this.looped) this.looped = 1;
if (this.looped++ > 2) this.stop();
Copy link to clipboard
Copied
sorry clay it wasnt to your standards, I will use your updated code from now on.
Cheers
Copy link to clipboard
Copied
Thank you for the tips @ClayUUID. You got me on the right track. After making the adjustments you suggested, the loop works as expected.
/*defined i=0 in first frame
placed this.gotoAndPlay("restart"); on last frame
placed "restart" label on first frame */
if (i < 3) {
i++;
} else if (i == 3) {
this.stop();
}
ClayUUID Nov 15, 2016 8:28 PM (in response to Tony Dilger)
ANSWER!
You initialize i to zero every time you enter the frame.
The variable i only exists in that frame.
The conditional logic doesn't account for i being equal to 2.
There's no such function as .play().
There's no need to use a frame label when you're just advancing to the next frame.