View Full Version : Counting # of times an MC plays?
shaoSTYL3
07-29-2003, 07:57 PM
i want Flash to count the number of times an attached movie clip loops, so that after a given amount of loops, i would move on to a different frame/scene.
what i tried was initializing a variable in my first frame (cnt = 0;) and then putting
cnt = cnt + 1;
in the first frame of the movie clip (i double clicked it from the library and clicked on frame 1 in its timeline, then wrote that in) but i dont' think that worked.
Anyone know how i would do this?
JHallam
07-29-2003, 08:09 PM
Ok, think about it, it's easy
you could do it a number of ways, why not just slap a function on the first frame or on the clip and a variable on the last frame of the clip? then just refferr from that variable? ;)
shaoSTYL3
07-29-2003, 08:55 PM
:confused:
i don't follow...
Sualdam
07-29-2003, 09:04 PM
You're actually close to having it right first time with your cnt = cnt+1 idea.
You need to set cnt=0 somewhere where it only gets set once. The first frame of the main movie is a good place.
Then, in the last frame of your movie clip where you loop from, put _root.cnt=_root.cnt+1. The '_root' part means 'the main timeline' - because the variable is scoped on the main timeline only - not inside the movie clip.
Now, depending on where you want to access the value of cnt from it will be incremented each time the clip plays and you just have to pick it up and do whatever you want to do with it.
The way you did it it would have been set back to 0 immediately after it was incremented to 1. However, if you looped back to frame 2 instead (with cnt=0 being in frame 1 of the movie clip), what you had would have worked first time :)
shaoSTYL3
07-29-2003, 09:14 PM
Originally posted by Sualdam
You're actually close to having it right first time with your cnt = cnt+1 idea.
You need to set cnt=0 somewhere where it only gets set once. The first frame of the main movie is a good place.
Then, in the last frame of your movie clip where you loop from, put _root.cnt=_root.cnt+1. The '_root' part means 'the main timeline' - because the variable is scoped on the main timeline only - not inside the movie clip.
Now, depending on where you want to access the value of cnt from it will be incremented each time the clip plays and you just have to pick it up and do whatever you want to do with it.
The way you did it it would have been set back to 0 immediately after it was incremented to 1. However, if you looped back to frame 2 instead (with cnt=0 being in frame 1 of the movie clip), what you had would have worked first time :)
thanks! i actually did initialize it in the first frame of the main timeline, but the thing was i didn't have the _root. prefixing cnt when i incremented it. :p
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.