-
Simple Flash web banner needs to loop 3x, how?
Hi, Im not sure why this isnt working...
I designed a very simple flash web banner and the requirement is to have it loop 3 times only. I entered this code at the last frame:
sample:
var i = 0;
if (i < 4)
{
gotoAndPlay(1);
i++;
}
else
{
stop();
}
trace(i);
obviously it isnt working... It keeps tracing 1 hence it just loops forever.. I know this is simple but I cant seem to get it pls help, thanks
-
That's because that variable is re-initialized to 0 every time you enter the frame.
What you need to do is initialize the variable in a frame that is not re-visited, such as the first frame, and then have your last frame point to the second (gotoAndPlay(2)), so as to avoid re-initializing your counter to 0.
Also, because you start with your counter at 0, this movie will actually loop 4 times. Either change the starting value to 1 or change the condition in the if-statement to be true only when i is less than 3, instead of 4. =)
Last edited by Nidht; 10-13-2009 at 09:53 AM.
-
Try this:
PHP Code:
var i:Number;
for(i=1; i < 4; i++) {
if(i<4) {
gotoAndPlay(1);
}
else {
stop();
}
}
trace(i);
I don't know if this is what you're looking for, but from what I read, it accomplishes what you're trying to do.
oops. thanks flo for pointing that out. I just cut and pasted and hadn't had my 2nd cup of coffee yet I think I might just stick to asking questions instead of trying to answer them.
Last edited by compjock; 10-13-2009 at 09:26 AM.
Reason: fix my stupid mistake.
-
i dont think you can use an 'if' statement like that, nidhts solution is proberly the best
-
compjock, because of how you have the for-loop setup, it will actually loop forever (as is the same in the original post). Every time the movie hits that frame, it sets i back to 1. Also, when the if-statement is satisfied, it will go to the first frame and the loop will be interrupted.
This is modified code for your final frame:
Code:
if (i < 4) {
gotoAndPlay(2);
i++;
}
else {
stop();
}
trace(i);
And this is code you should place in your first frame:
Try it out and let us know what happens. =)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|