Groups | Blog | Home
all groups > flash actionscript > february 2004 >

flash actionscript : SetInterval Problem


benmaxwood NO[at]SPAM aol.com
2/16/2004 8:46:08 PM
Hello
What I have is some checkboxes that call and play swfs one after the other
when I check them and click on the submit button. However I need them to play
at different durations and my current script will only play them each for the
same duration then go onto the next one even though the swf has not finished

Here is the script
On the timeline I have this script
i = 0
function playMovies()
playMovie.loadMovie(choiceArray[i])
trace(choiceArray[i])
if ((i+1) < choiceArray.length)
++i
}else
i = 0




then on the submit button I have this script
on (release)
choiceArray = new Array()
if (box1.selected == true)
choiceArray.push("a_movie.swf")

if (box2.selected == true)
choiceArray.push("b_movie.swf")

if (box3.selected == true)
choiceArray.push("c_movie.swf")

if (box4.selected == true)
choiceArray.push("d_movie.swf")

if (box5.selected == true)
choiceArray.push("e_movie.swf")
}
playMovies()
setInterval(playMovies, 2000)


SetInterval at 2000 will play each movie for about 2 seconds but I need each
movie to play at different lengths
Does anyone have any ideas

By the way my e-mail is benmwood45@hotmail.com not benmaxwood@aol.co
I would really appreciate any help anyone can give
Thanks
Be

pazzoboy
2/16/2004 10:09:29 PM
I'm stretching it here, because I've never tried it, so forgive me if it
doesn't work. If youcan play your movies in reverse order, put this on the
main timeline
while(choiceArray.length>0){ //while the array has any element
for(x=choiceArray.length-1;x>0;x--){ //loop through the arra
if(eval(choiceArray[x]._currentframe)==eval(choiceArray[x]._totalframes){
//if the current movie has played throug
choiceArray.pop(); //remove last element from the array
choiceArray[x].play(); //play the movi
break; //stop the loop - it's not needed anymor



You might have to experiment with the eval() method. I don't have flash on
this PC so I can't check it right now.
So, essentially, you play the last movie selected. The setInterval() runs the
function again...if the last movie in the array has reached its last
frame(i.e., is no longer playing), it is removed from the array. If it's the
first time through the loop, it won't be, eh? So, after the last movie is
removed, the one before it suddenly becomes the last movie. The next line
plays it. I throw a break; in there at the end so the loop doesn't have to
work any more than it needs to

Like I said, you might have to fiddle with the syntax, but the concept should
work

pazzoboy
2/17/2004 12:48:33 PM
//Latest version after a couple of tries. Anyone know how to check
currentframe and totalframes for an imported swf?
//What I have here is for movieclips...

//submit button
on (release)
if(_root.box1.getValue()==true)
_root.choiceArray.push("a_movie.swf")

if(_root.box2.getValue()==true)
_root.choiceArray.push("b_movie.swf")
}
if(_root.box3.getValue()==true)
_root.choiceArray.push("c_movie.swf")
}
----------------
//main timeline:
setInterval(_root.playMovies,2000)


choiceArray = new Array()

function playMovies()
//trace("got to the function")
//for(y=0;y<choiceArray.length;y++)
// trace(choiceArray[y])
//

for(x=choiceArray.length-1;x>0;x--){ //loop through the arra
if(choiceArray[x]._currentframe==choiceArray[x]._totalframes){ //if the
current movie has played throug
trace(choiceArray[x] + " playing...move on to the next movie")
choiceArray[x].setValue(false)
choiceArray.pop(); //remove last element from the array
//choiceArray[x].play(); //play the movi

else{trace("keep playing current movie");



kglad
2/17/2004 3:21:51 PM
pazzoboy, you can't access _currentframe etc of choiceArray elements. those
are external movieclip strings, not loaded movieclip strings. if they were
movieclip strings you'd need to instruct flash to resolve the strings into
object names by using eval or bracket notation
benmax, you could create an array containing the duration you want each
movieclip to play and then use that array instead of a fixed time within
setInterval. you'd need to clear each setInterval after one call and create
the next setInterval
pazzoboy
2/17/2004 3:35:17 PM
Kglad, thanks for setting me straight...I had a feeling accessing _currentframe
of a swf wasn't possible. I guess one could pass the durations as arguments of
the function call, eh

My other suggestion would be to just create movieclips and copy/paste the
frames of the other movies into the movie clips, and then just play them.
Haven't succeeded with that one, probably because in a momentary lapse of
reason, I got rid of the eval() method...
kglad
2/18/2004 2:28:26 AM
AddThis Social Bookmark Button