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

flash actionscript : pausing a movie for a set interval



tralfaz
3/5/2004 2:38:19 PM
[quoted text, click to view]

It looks fine.. and tests fine too. Zip your source code, put on a website
and post a link to it. That's better than sending it to one particular
person. (although you are welcome to send it to me if you want to)
tralfaz


_Icarus_
3/5/2004 10:03:46 PM
I'm trying to create a function that allows me to pause a movie for whatever
amount of time I want on a particular frame using this code in Flash MX:

on the first frame:

function pause(){
play();
clearInterval(timer);
};

on the frame I want to pause the movie on:

stop();
timer = setInterval(pause, 3000);
//where 5000 is 5 seconds of pause or 60000, 1 minute.

In the above example I want to pause the movie for 3 seconds while something
happens then I have a stop action on a later frame to stop the movie completely.

My problem is that it seems to work sometimes and other times it doesnt...in
other words its a bit erratic and when the movie comes to just the stop action
it passes right by it.

Can anyone see anything wrong with this code????

I would be more than willing to send anyone the code if they are willing to
take a look at it.

Thanks

jerreye04
3/6/2004 7:38:32 AM
This the pause script I personally use:

stop();
theWait = 5000;
function pause() {
if (startTime == null) {
startTime = getTimer();
endTime = startTime+theWait;
}
if (startTime>=endTime) {
stop();
} else {
startTime = null;
play();
}
}
pauseInt = setInterval(pause, theWait);
tralfaz
3/8/2004 1:10:55 PM
[quoted text, click to view]

What was wrong with your original code? It would do exactly what you wanted
without any code bloat. I don't see any advantage to having two timers.
setInteval will call the pause function once, 3 seconds after you set it..
why use getTimer too? It is important also to turn off the interval timer
after you stop using it, otherwise you will waste cpu clock cycles servicing
an unneeded timer. The original code takes care of that too.
tralfaz

_Icarus_
3/8/2004 8:35:45 PM
thanks a lot jerreye04, that code works good ...only problem is that it sounds
like the browser is refreshing every second , manually counting the time. At
least in Internet Explorer it keeps clicking like it would as if you were
refreshing the window manunally.

Have you come across this?

_Icarus_
3/8/2004 8:54:48 PM
I have posted the file so you can see:

[L=Here is the link]http://www.bconnex.net/~davel/findajob/findajob.html[/L]

_Icarus_
3/8/2004 10:34:40 PM
My original code somehow ignored the basic stop action so what I wanted to do
was have the timeline pause for say 3 seconds then play for a bit then pause
again and eventually come to a complete stop where the user would select a next
button to continue.

With the original script it would pause for 3 seconds and then ignore the stop
action and continue on its merry way on the timeline.
jerreye04
3/8/2004 10:36:12 PM
If you are going to use the "pause" code I posted, you need to have at least 2
frames to work with. I think you are navigating from frame to frame correct? If
so, that would explain the "clicking" in IE. Look at the code and you will
notice that it looks for the value of the "theWait" variable. The movie goes
back one frame and loops until the "lapsedTime" is greater than "theWait", then
the movie will continue.

I agree with tralfaz in that your "pause" code should work just fine. In fact,
I like it better than the one I showed you :) I tested your code and it works
perfectly.

BTW: My audio card on my machine is not working at the moment, so I cannot
tell if you are using streaming audio in your movie. If so, there is a
possibility that that is the reason why it may skip a frame and possibly ignore
the code in the frame it skipped. Streaming sound has priority over frames in
Flash and will skip frames in order to keep the audio smooth.
_Icarus_
3/8/2004 10:54:09 PM
My only problem with the original code was that it ignores the stop action for
some reason eventually.

Let me try and explain better...

As you could see [L=from the posted
link]http://www.bconnex.net/~davel/findajob/findajob.html[/L] the movie clip I
am working on is basically a self running presentation that stops at the end of
each section were the user will select the next button to continue, so what
happens is I have text fade in and then i want it to pause for a few seconds so
the user can read that then more text fades in then the timeline comes to a
stop so the user can read all the information until they are content then they
press the next button to continue.

Thus I would like to pause the movie for say 4 seconds then continue then
pause the movie for a few seconds then come to a complete stop. When I use the
original code for some reason the movie ignores the stop action and keeps
playing right through.
jerreye04
3/8/2004 11:18:23 PM
that is strange. I don't think it has anything to do with the pause function
tho.

The pause function should be on frame 1. You would then use this code on
anyframe you want to pause:

stop();
timer = setInterval(pause, 3000);

After the timer reaches 3 sec, the movie continues playing. If you want the
movie to stop anytime after this, just use:

stop();

Maybe you should send me your fla so I can see what you are doing. If you
want, just zip it and send to your server. Then send me the link.
__icarus__
3/9/2004 3:55:34 AM
I have attached the file to this message.

jerreye04
3/9/2004 4:29:18 AM
tralfaz
3/9/2004 10:09:39 AM
[quoted text, click to view]


On all your next and previous arrows, stop the interval timer from running
before moving to the next section, otherwise you can end up with more than
one timer going at once...

on (release) {
clearInterval(timer); // clear the timer before moving on
gotoAndPlay("pg9");
}


Here's another suggestion for code improvment (although it won't work any
differently):
Whenever code seems to be repeated a lot, it is a good candidate to become a
function call, like this...

In any frame where you want to pause:

waitHere(2000); // wait for 2 seconds at this frame


On the first frame define the functions:
function pause(){
play();
clearInterval(timer);
};

function waitHere(howLong) {
stop();
timer = setInterval(pause, howLong);
}



You did a great job on your slide presentation. It looks very professional.
tralfaz

tralfaz
3/9/2004 10:17:53 AM
[quoted text, click to view]

A note about troubleshooting this problem.. I saw that when I clicked on the
arrow keys to move to the next section, that's when the pause behavior
became erratic. I suspected that multiple timers were running after the
click. To test the theory, I put a beep sound inside the interval timer so
that I could hear when the timer was activated. You can also do the same
thing by printing a text message on the screen but then you have to erase
the text later. A sound is easier. To add a beep sound, import a short
beep sound into the library and assign it a linkage name, like "beep".

This is the code to use a beep sound for troubleshooting purposes....

onLoad = function() {
s = new sound();
s.attachSound("beep");
}

function pause(){
play();
clearInterval(timer);
s.start(); // make a beep sound here
};

function waitHere(howLong) {
stop();
timer = setInterval(pause, howLong);
}

I use this method sometimes to track down problems like this. You might
find it useful.

HTH
tralfaz

__icarus__
3/9/2004 3:03:05 PM
jerreye04
3/9/2004 7:27:53 PM
After viewing your fla:

You need to include the clearInterval(timer) on all button instances. If they
are not present on each button, then when you click one, the timer will still
be running in some cases, which will cause headaches :)

I fixed all those problems for you. I also put all the nav buttons all one
layer so they are easier to find and modify if ever needed. It is good practice
to always (if at all possible) keep elements such as buttons together, as well
as keep all code/callbacks on one frame - usually frame 1. All in all, good job
so far.

What is your email so I can email it to you?
__icarus__
3/9/2004 7:57:46 PM
tralfaz, jerreye04 you guys are awesome!!! thank you so much for your help,
your amazing! I was thinking about clearing the timer on release but I wasnt
sure what the correct syntax was.

My email address is davel@bconnex.net.

Thanks again guys!!!


jerreye04
3/9/2004 8:20:40 PM
AddThis Social Bookmark Button