|
From: Paedia on 6 Feb 2006 16:49 I want to pause a Flash show for 10-30 seconds at various times during the movie. Is there a way to do this in Action script, rather than inserting a bunch of empty frames?
From: David Stiller on 6 Feb 2006 17:10 Paedia, > I want to pause a Flash show for 10-30 seconds at various > times during the movie. Is there a way to do this in Action > script, rather than inserting a bunch of empty frames? You betcha. This question comes up a lot. Plus, it probably makes more sense to ask it in the ActionScript forum. ;) That said, one basic approach is to use the setInterval() function, which triggers whatever other function you supply at whatever interval you supply. The other function you trigger could be play(), for example. So if you stop(), then instruct setInterval() to play() after 30 seconds, you're set. The only catch is that setInterval() *continues* to trigger the supplied function until you tell it to stop. To stop a given interval, you use clearInterval() and supply the relevant interval id as a parameter. How do you know what interval id is the correct one? Well, setInterval() returns a value when invoked, and the value it returns is a number -- that's your id. So you can store it in a variable and use it with clearInterval(). Here's the starter. var id = setInterval(); There's our variable, set to accept the return value of setInterval(). Now, this function takes at least two parameters ... var id = setInterval(function(){}, 30000); .... the first is our function, the second is a 30 second interval (that's 30,000 milliseconds). Let's break this over two lines, so it's easier to read: var id = setInterval(function(){ }, 30000); Okay. Now, let's populate that function in the first parameter. We want it to invoke the play() method of the MovieClip class, since the main timeline is a movie clip. We can reference the main timeline with _root ... var id = setInterval(function(){ _root.play(); }, 30000); .... and we want to clearInterval() with that id variable. var id = setInterval(function(){ _root.play(); clearInterval(id); }, 30000); Of course, start the whole thing off with the MovieClip.stop() method. this.stop(); var id = setInterval(function(){ _root.play(); clearInterval(id); }, 30000); David stiller (at) quip (dot) net "Luck is the residue of good design."
From: alohaarts on 6 Feb 2006 17:23 yes there is. using timers methods from the Date object. try creating an algoritm that calculate the mathematical difference ( a - b ) between getSeconds() or getMinutes(). eg: - get the current time when the movie stops - then calculate when current streaming time - 10 seconds = time when movie stopped, function 'refreshed' by setInterval()
|
Pages: 1 Prev: Print a list of random numbers. Bingo card. Next: New to Flash 8 and Bitmap scaling |