Skip to main content
Inspiring
July 22, 2006
Question

Wait on frame until video finishes?

  • July 22, 2006
  • 6 replies
  • 455 views
Hello,

Does anyone know if there's a way to tell flash to wait on a frame until a video finishes playing, and then go to the next frame? (I'm using progressive download. It has audio that needs to stay in sync.)

Thank you for your help!
This topic has been closed for replies.

6 replies

Inspiring
July 23, 2006
kalibahlutwo,

> I really appreciate your help! Thanks again! :-) You're a
> fantastic teacher!

Thanks for the kind words. :) I remember what it was like when I first
started. A good nudge in the right direction can be a tremendous help.
Good luck with it!


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."


Inspiring
July 22, 2006
Briliant!! David, thank you so much for taking the time to explain about classes and objects. I'm going to look up the classes you mentioned and learn more. I really appreciate your help! Thanks again! :-) You're a fantastic teacher!
Inspiring
July 22, 2006
> Finally, our FLVPlayer instance, vp, invokes the
> VideoPlayer.addEventListener() method to become
> a listener for "complete" events from the listener
> object.
>
> Done. Badda bing. :)

I should have mentioned, you'll want to add a stop() action before any
of the previous code. Obviously, we want the timeline to stop first, then
handle the complete event.


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."


Inspiring
July 22, 2006
kalibahlutwo,

> I have imported an FLV and on import chose "progressive",
> rather than embedding the video, because I read that if the
> video has audio in it, it will stay syncronized better with
> progressive than with embedded video.

I can neither confirm nor deny which plays better. But it's good to
know we're dealing with external video.

> Flash automatically put the video into an FLVPlayback
> component.

Yupper. :) Now we're getting warmer.

> I would like to have the video play to the end, and then
> have the Flash movie automatically go to the next frame.

Here's the scoop. Just about everything in ActionScript can be
described as an object. Objects are defined by something called classes,
which you may think of as object blue prints. The FLVPlayback Component,
for example, is defined by the FLVPlayback class, and you can look up this
class entry in your documentation. Components are listed in the Component
Language Reference and ActionScript clases are listed in the ActionScript
2.0 Language Reference.

Classes define the properties of an object (the characteristics it has),
its methods (things it can do), and its events (things it can react to). So
class entries should definitely be your first stop, always. If you're
dealing with a movie clip, look up the MovieClip class. If you're dealing
with a dynamic or input text field, look up the TextField class, and so on.

Consulting the FLVPlayback class, then, we find that "FLVPlayback
extends the MovieClip class and wraps a VideoPlayer object.." Okay, what
does that mean? Well, in this context, it means that any FLVPlayback
instance -- such as the one on your Stage -- contains all the features
(properties, methods, and events) of a movie clip, because it *extends* the
MovieClip class. So this particular case is something of a wild goose
chase. Normally, the answers you want are already at hand. FLVPlayback is
a little different. But the documentation continues: "... and wraps a
VideoPlayer object," so now we know to get more information by looking up
the VideoPlayer class.

Bingo. Here's were we find the answer. The VideoPlayer class includes
an event VideoPlayer.complete (see the Events summary in its class entry).
It also contains a method VideoPlayer.addEventListener(), which means we can
"listen" for the complete event. Good news.

So ... give your FLVPlayback Component instance an instance name.
Select it and look at the Property inspector. Let's name it vp, short for
video player. Create a new layer and name it "scripts" -- this is where
we'll put your ActionScript.

var listener:Object = new Object();
listener.complete = function() {
trace("complete!");
};
vp.addEventListener("complete", listener);

Here's what's going on. Events of the sort we're dealing with can be
handled with a listener. A listener is just a generic Object instance -- so
in line 1, we're declaring a variable arbitrarily named listener. It's of
type Object and is set to a new Object instance.

This listener object acts as a proxy for the FLVPlayer (actually, the
VideoPlayer) complete event. Via this listener, we assign a function to a
complete property. In this example code, I'm simply having it trace() the
string "complete!" to the Output panel. You'll want to have it send the
main timeline to frame 2 -- _root.gotoAndStop(2);

Finally, our FLVPlayer instance, vp, invokes the
VideoPlayer.addEventListener() method to become a listener for "complete"
events from the listener object.

Done. Badda bing. :)


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."


Inspiring
July 22, 2006
Hi David,

Thank you for your reply! I have a flash movie with 2 frames, and on the first, I have imported an FLV and on import chose "progressive", rather than embedding the video, because I read that if the video has audio in it, it will stay syncronized better with progressive than with embedded video. On import, Flash automatically put the video into an FLVPlayback component. I would like to have the video play to the end, and then have the Flash movie automatically go to the next frame.

Sorry for not being clear before and thank you for taking the time to ask for clarification to my vagueness. :-)
Inspiring
July 22, 2006
kalibahlutwo,

> Does anyone know if there's a way to tell flash to wait
> on a frame until a video finishes playing, and then go to
> the next frame?

Sure thing. :)

> (I'm using progressive download. It has audio that
> needs to stay in sync.)

Progressive download of what -- the video? Audio needs to stay in sync
with what -- the video, or maybe a movie clip in the Flash movie?

> Thank you for your help!

I'll be glad to help, but I'll need a bit more information. How are you
displaying the video? One of the Media Components, FLVPlayback Component,
something else?


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."