PDA

View Full Version : pause and resume movie


eef
10-31-2003, 01:08 PM
Hello, I am pretty clueless when It comes to action script (or any kind of script)... I am making a movie where there are parts where words come up and I want to give the watcher enough time to read the words. I know I can just put in tons of frames- but I was wondering if there is a pause and resume method I might be able to use with action script. Something to holed a movie at a certain frame for a certain amount of seconds and then resume until the next pause. Make sense?

If anyone knows a way to do this please help. And please speak and super ignorant laymens terms.

Thanks!
-eef

nunomira
10-31-2003, 07:33 PM
hi,

you can define this function wait():

function wait() {
stop();
var myInterval = setInterval(function () {
play();
clearInterval(myInterval);
}, 2*1000); // stop for 2 seconds
}

and then, call the function from the frame where you want to movie to stop playing:

wait();

eef
11-03-2003, 11:50 AM
Thanks-
like I said I really don't know much more than the simplest of action scripting like stop play and goto and play type commands. All the other stuff is just confusing.

Could you explain to me how I use what you gave me- where do I set the amount of time I want my movie to pause- and how do I make it a function?

Hope I'm not wastin anyone's time. Thanks allot for helping.
-eef

nunomira
11-03-2003, 12:15 PM
You attach the code that defines the function to the first frame of the main timeline.
And you attach the function call to the frame where you want the movie to pause.

The 2 in the function sets a 2 second pause. Change it as you wish

If you're calling the function from a different timeline, you can define a similar function but with parameters:

function wait(mc, n) {
mc.stop();
var myInterval = setInterval(function () {
mc.play();
clearInterval(myInterval);
}, n * 1000);// stop for n seconds
}

as the first parameter you allways use this, and as the second parameter you use the number of seconds you want the movie to stop:

_root.wait(this, n);

eef
11-03-2003, 12:47 PM
THATS AMAZING! IT WORKED! THANK YOU FLASH MASTER!
-eef

eef
11-03-2003, 03:37 PM
Ok- now that that problem is solved, here is problem 2-
Is there anyway to apply that to a movie clip that is animating also? I have a movie clip of a man walking across the screen and when the movie pauses he stops in his place, but he keeps walking in place and 2 seconds later starts moving again.

Can I apply that to my movie clip instance? Say the movie clip instance name is "man1."

thanks again for your help.
-eef

nunomira
11-03-2003, 05:30 PM
something like:

function wait(mc, n, other_mc) {
mc.stop();
other_mc.stop()
var myInterval = setInterval(function () {
mc.play();
other_mc.play()
clearInterval(myInterval);
}, n * 1000);// stop for n seconds
}

and

_root.wait(this, n, man1);

eef
11-03-2003, 06:35 PM
You are my hero. Thanks so much. I dont understand how you did it but you did it and it worked.
-eef

eef
11-06-2003, 06:49 PM
would you be willing to explain that code to me? It kind of makes sense but other parts just confuse me... or someone who understands?
-eef

nunomira
11-06-2003, 07:34 PM
here's the explanation of the code

/*
Function definition: lets call it "wait"
The function has 3 arguments:
- mc -> the timeline you want to stop and then play
- n -> the number of seconds you want to stop
- other_mc -> the other mc you want to stop and then play
*/
function wait(mc, n, other_mc) {
mc.stop();
other_mc.stop();
// use setInterval to trigger something n seconds later
// and assign it a variable "myInterval" so you can clear it later
// otherwise it would repeat the same action forever
var myInterval = setInterval(function () {
mc.play();
other_mc.play();
clearInterval(myInterval); // now that everything is playing again, clear the interval
}, n * 1000); // n*1000 milliseconds = n seconds
}


There are only two points here:
- the definition of a function.... you have to understand functions...
- the use of setInterval()...

Here, setInterval() is writen in a more complex way than usual...
I can give you a simple exampleof how write it in a more readable way:

// this function just outputs "hello"
function sayHello() {
trace("hello");
}
// use setInterval to call the functon every 500 milliseconds
setInterval(sayHello, 500);

And the same, but with the function defined inside setInterval(), like in the main piece of code, which is not so readable:

setInterval(function () {
trace("hello");
}, 500);


The use of clearInterval():

function sayGoodbye() {
trace("good bye");
clearInterval(myInterval);
}
myInterval = setInterval(sayGoodbye, 500);

The function is only called once because once it is called by the interval myInterval, clearInterval() is called and deletes the interval.

eef
11-07-2003, 11:46 AM
mm k... it's starting to make sense. Thankyou so so much for explaining all that... I'm sure I'll have to reread that post like 7,000 times before I really start to get it, but that's howmy mind works.
-eef

meechp123
07-30-2004, 03:25 PM
Wow, one year later and this post helped me with my issue! Thanks nunomira and eef for asking this question!

nunomira
07-30-2004, 04:16 PM
:)

And I highly respect you for searching before asking!
That's the way to go and the best way to learn!

And... welcome to ActionScript.org

mshirey
08-03-2004, 06:51 PM
Heh, I too was helped by this, thank you!

meechp123
08-23-2004, 09:05 PM
:)

And I highly respect you for searching before asking!
That's the way to go and the best way to learn!

And... welcome to ActionScript.org

I definitely agree, I always google before posting.

Connie Lippert
09-25-2004, 02:59 AM
Thanks from me too..exactly the same problem I'm having as a newbie also!

aeris
01-27-2005, 10:48 AM
A thanks from me too :)

Cheers !

fyulaba
07-05-2005, 04:37 AM
Wow, one year later and this post helped me with my issue! Thanks nunomira and eef for asking this question!

2 years later and it answered my question too! :p

preacher28
07-05-2005, 05:40 PM
Just helped me too!

preacher28
07-05-2005, 06:30 PM
Oops... I spoke too soon!

What I am looking to do is pause the mc for 4 seconds and then go to frame 5 of the timeline. In my timeline I have an action in frame 2 saying:

function wait() {
stop();
var myInterval = setInterval(function () { gotoAndPlay(5);clearInterval(myInterval);}, 4*1000);
}
wait();

which works perfectly. But if while that is paused, if the user clicks a button with the nextframe action on it, it sends the timeline to frame 3 with this actionscript on it:

gotoAndPlay(27);

which sends the playhead to frame 27. Perfect right? Not quite. What is happening is when the interval runs out (4 seconds), even though the timeline is now on frame 27, it sends it back to frame 5! How do I clear the interval. I have tried:

var myInterval = clearInterval(myInterval);

as it is exactly what I am looking to do but it completely ignores it.


Any ideas? Any answers could help people 2 years down the road!!

carlos_abreu198
07-05-2005, 07:05 PM
me too be helped by this
thanks for all

weisswolfen
07-13-2006, 12:01 PM
I'm new and I don't know if this is the right place to post this question, I have used the AS posted at this site-http://www.actionscript.org/forums/showthread.php3?t=37008

function wait() {
stop();
var myInterval = setInterval(function () {
play();
clearInterval(myInterval);
}, 2*1000); // stop for 2 seconds

and called the funcion from the frame ...

wait();

Now it works well, in my page shows at interval different logos, but after a minute or so just shuts down.
One more thing for the logos I'm using in the same scene of the LOGO'S movie a As to speed up frame rate for certain frames , has anyone any idea why this happen or if the two different AS interfere with each other? Thank you.

Switzerland
08-02-2006, 06:49 PM
hi,

you can define this function wait():

function wait() {
stop();
var myInterval = setInterval(function () {
play();
clearInterval(myInterval);
}, 2*1000); // stop for 2 seconds
}

and then, call the function from the frame where you want to movie to stop playing:

wait();




I thank you very much for this great help

but ... can you tell me what the stupid thing I did that made my movie invisible.... ??? I have attached my .fla.

Switzerland
08-03-2006, 10:34 PM
I thank you very much for this great help

but ... can you tell me what the stupid thing I did that made my movie invisible.... ??? I have attached my .fla.

Any help ???

a5c3ndant
04-25-2008, 01:41 AM
how do i use this wait function for a 1-frame movie? it is an interactive flash and all the code is in frame 1 and there is no frame 2. i want to simulate a pause for n seconds but i cant do it. For example, on click of a button, bring a movie clip on stage, wait for 2 seconds, then remove the movie clip