Search code examples
javascriptflashswfobject

How to send a seek event to player embedded with SWFObject 2.2?


I have updated my SWFObject to 2.2 from 1.5 and now need to replicate some old functionality that used to work in 1.5, viz an event jumping to a certain point in the video.

Here's the contents of my script tag:

var flashvars = {
    file: '79834.flv',
    autostart: 'true',
    displayclick: 'mute',
    repeat: 'single',
    start: 0
};
var params = {
    allowfullscreen: "true",
    allownetworking: "all",
    allowscriptaccess: "always"
};
swfobject.embedSWF("player.swf","main","500","400","9.0.0", "false", flashvars, params);

var player;
function playerReady(obj) {
    player = document.getElementById(obj.id);
    alert(player);
    setTimeout("seek()", 1000);
}
function seek() {
    player.sendEvent("SEEK", 100);
}

The top half is what I've replaced the old V1.5 code with.

The bottom half (from "var player") is what no longer works. playerReady is still happening, but apparently obj.id is now "null". Is there a new correct way to find the player element? Or a different way to implement a seek event?


Solution

  • You missed the id attribute:

    var attributes = {
        id: "playerID"
    }
    // and later
    swfobject.embedSWF("player.swf","main","500","400","9.0.0", "false", flashvars, params, attributes);