Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nextFrame() on FLV complete 1

Status
Not open for further replies.

dmears1

Technical User
Jun 18, 2003
208
US
I need to be able to go to the next frame in a scene when FLV is completed. I've tried the following AS:
Code:
var myListener = new Object();
myListener.complete = function(eventObject) {
	nextFrame();
};
video.addEventListener("complete", myListener);

But it does not seem to work. You can view the videa at It is the Video in on the right-hand side of the page.

I've consulted with the Help files in Flash MX 2004 and I can't seem to find where I'm going wrong. Thanks in advance for any help.

 
Is "video" the instance name of your MediaDisplay or MediaPlayback component?
 
Well that appears to be correct then. Could it be that nextFrame() is what is getting you? That is not a play command. The play head will go to the next frame and stop when you use nextFrame(). Perhaps gotoAndPlay(nextFrameNumber) would work better for you?

Wow JT that almost looked like you knew what you were doing!
 
Thanks pixl8r,
I've tried gotoAndPlay(frame#); _root._currentframe+1; pretty much exhausted any means of proceeding to a different frame and can't seem to get it to work. It's as if the complete feature of the MediaDisplay isn't registering.

 
Just a typo. It is "video" that I have as an instance name. Thanks for pointing it out though, it wouldn't be the first time I've made a mistake as simple as that.

I've placed this script in the same frame that the MediaDisplay is in. Am I correct in putting the AS in a frame rather than on the MediaDisplay component itself?

 
Yep. Your script goes to the timeline, not to be attached to the component.

You can do a very quick test. Make a barebones movie with just 2 frames. 1st frame with MediaDisplay component ("video”) and the 2nd frame with a text says "Frame 2".

Script for the 1st frame:
[tt]//
stop();
var myListener = new Object();
myListener.complete = function(eventObject) {
nextFrame()
};
video.addEventListener("complete", myListener);
//[/tt]

Script for the 2nd frame:
[tt]//
stop()
//[/tt]

When your FLV finishes the screen should move to "Frame 2".

Kenneth Kawamoto
 
Would that work just as good if you had the flv in another scene? and change the code to
Code:
myListener.complete = function(eventObject) {
    gotoAndPlay("Scene 1", 1);
and on that frame a button to go back to the first scene
 
Hey Kenneth & Wulfgen,
THanks for the suggestions. I tried yours Kenneth and it still doesn't work-even with just 2 frames. I did notice that when the video ends, you can right-click and select "forward" and it will go to the next frame then.
I also tried Wulfgen's suggestion of trying multiple scenes and this also produced the same results.
I really believe that for some reason the "complete" event isn't registering.

 
If that barebones test didn't work, then it's a problem!

There have been some reports that sometimes MediaDisplay component stops playing FLV 1 frame before the end and therefore "complete" will never get fired.

Doesn't your case sound exactly like this?

This kind of quirks puts many people off from using Components. "Don't use them, or create your own Components." - but I suppose this isn't very helpful answer!

One hack is to check if the FLV is playing or not. If not playing, it must be finished, so that it can proceed to the next frame.

[tt]// main timeline
stop();
onEnterFrame = function () {
if (!video.playing) {
nextFrame();
delete onEnterFrame;
}
};
//[/tt]

Other thing you can try is to re-export FLV with the latest encoder. May be you should try this first.

Kenneth Kawamoto
 
I found a working solution here: Then click on Media.complete about halfway down the page.
If you look at the bottom of this page at the comments section, you'll see a solution for FLVs containing audio which requires setting a cuePoint. When I implemented this suggestion it worked.
I would still love to know why my original code does not work. It is nearly identical to what is found in Macromedia's livedocs.
Thanks again for all the help.

 
Hey Kenneth,
Yeah, it does seem like the FLV was ending just before the complete event was ever reached.
I typically don't like to use components but I needed this up there ASAP (bosses don't like to wait, ya know?) and as I'm not too experienced with video in Flash thought this would be the quickest way.
BTW, I did try something very similar to your if(!video.playing) script, however, I didn't have it in a onEnterFrame function. Probably why it didn't work for me.
Thanks Again!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top