简体   繁体   中英

How to listen for events with swfobject (like "onVideoEnded")

I am embedding a swf movie into my html with the static publishing method of swfobject:

<object id="swf" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="400" height="300">
    <param name="movie" value="some.swf" />
    <param name="play" value="false" />
    <param name="menu" value="true" />
    <param name="allowFullScreen" value="true" />
    <param name="loop" value="false" />
    <param name="FlashVars" value="javascriptCallbackFunction=onJavaScriptBridgeCreated" />
    <!--[if !IE]>-->
    <object type="application/x-shockwave-flash" data="some.swf" width="400" height="300">
    <!--<![endif]-->
      <p><a href="http://www.adobe.com/go/getflash">
        <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
    </a></p>
    <!--[if !IE]>-->
    </object>
    <!--<![endif]-->
  </object>

I want to trigger a Javascript function after the video had finished and tried with the above callback function in the flashvars parameter. My Javascript function looks like this:

function onJavaScriptBridgeCreated(playerId) {
var player = document.getElementById(playerId);
player.addEventListener("complete", "completeFunc");}

and

function completeFunc() {
alert('video ended');}

I found this approach at http://forums.adobe.com/thread/791624 and modified it for the static publishing method ( http://code.google.com/p/swfobject/wiki/documentation ).

But the problem is, the function completeFunc is never called and I can't figure out why.

I would be very glad if you could help me out.

I can't speak to the onJavaScriptBridgeCreated code, but your SWFObject code is incorrect, you need to include the <param> node in BOTH <object> nodes, like so:

<object id="swf" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="400" height="300">
    <param name="movie" value="some.swf" />
    <param name="play" value="false" />
    <param name="menu" value="true" />
    <param name="allowFullScreen" value="true" />
    <param name="loop" value="false" />
    <param name="FlashVars" value="javascriptCallbackFunction=onJavaScriptBridgeCreated" />
    <!--[if !IE]>-->
    <object type="application/x-shockwave-flash" data="some.swf" width="400" height="300">
        <param name="play" value="false" />
        <param name="menu" value="true" />
        <param name="allowFullScreen" value="true" />
        <param name="loop" value="false" />
        <param name="FlashVars" value="javascriptCallbackFunction=onJavaScriptBridgeCreated" />
    <!--<![endif]-->
      <p><a href="http://www.adobe.com/go/getflash">
        <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
    </a></p>
    <!--[if !IE]>-->
    </object>
    <!--<![endif]-->
  </object>

The only exception is the 'movie' param, which is only used by IE in the first <object>

i have solved this by using flowplayer. its very easy to use and offers sufficient configuration possibilities. thanks for your help anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM