开发者

Play a 2nd flash video after the first ends

I have a flash object set up in the standard format:

<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
swfobject.embedSWF("swfplayer.swf", "myContent", "300", "120", "9", "expressInstall.swf");
</script>

but I 开发者_开发技巧want to start playing a second flash video on a different part of the web page the moment the first video ends. Is there a kind of listener of some sort to use?

Thanks


There actually is a way to do this, providing you movie is more or less timeline based. There's a couple calls that you can make to the flash object through javascript that will return you values you can check against to determine if the movie is complete.

To retrieve the current frame of the movie use:

document.getElementById("myFlashObject").TCurrentFrame("_root");

To check if the movie is playing use:

document.getElementById("myFlashObject").IsPlaying()

If the movie is stopped on a frame using the "stop()" method, this will return false. There's quite a few other methods you can use as well that you might find useful in playing the other movie. Here's a link to the Adobe reference docs:

http://www.adobe.com/support/flash/publishexport/scriptingwithflash/scriptingwithflash_03.html

Note: I tested this and it works with the flash player 10 in firefox. You may want to double check the cross-browser compatibility of these methods.


You could approach it from these two possibilities: LocalConnection or ExternalInterface.

I would go with ExternalInterface personally. With it, you can set up a javascript function that receives a call from videoPlayer_1 when its video has ended. To this javascript function you could pass an ID to determine which player has finished, and then send a call back up to the appropriate next player to tell it to start playing. You could repeat this process as many times as you have/swf's with videos.

I would have included an example but you didn't mention as2 or 3.

As for LocalConnection, you could create a group of movies with a local data connection, but this is easily broken by certain scenarios of multiple browsers/swfs, so probably not the most reliable method. However if you wanted to give it a shot, look up Grant Skinner's SwfBridge class to make things much easier.


Look at Detecting end of Flash movie in javascript

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜