SWFOBJECT CurrentFrame Javascript

做~自己de王妃 提交于 2019-12-04 21:07:53

At a quick glance, I see three problems with your code.

  1. By specifying an ID and name in your attributes object, you're assinging a name to the newly created <object>. This means swfobject.getObjectById("myAlternativeContent") won't work, because you've renamed the <object> to "flashDiv". You should use swfobject.getObjectById("flashDiv") instead.

  2. You're trying to use swfobject.getObjectById immediately after swfobject.embedSWF. However this probably won't work, because the embed might not be completed before swfobject.getObjectById is invoked. (BTW, getObjectById is only needed for static publishing; when using dynamic publishing, it's ok to use the standard getElementById)

  3. You're not specifying the express install parameter, so your SWFObject syntax is invalid. Use this instead:

.

swfobject.embedSWF(flashname, "myAlternativeContent", "800", "600", "9.0.0", false, flashvars, params, attributes);

.

A solution to #1 and #2 is to use SWFObject's callback feature. This helps with timing by ensuring you won't invoke your DOM functions until the embed is successful. It also provides a reference to the embedded <object> which enables you to avoid making the swfobject.getObjectById call.

function flashplayer(flashname) {

    var flashvars = {};
    var params = {};
    params.play = "true";
    params.menu = "true";
    params.scale = "noscale";
    params.allowfullscreen = "true";
    var attributes = {
        id: "flashDiv",
        name: "flashDiv"
    };
    function mycallback(event){
        var obj = event.ref;
        totalFrames = obj.totalFrames;
        $('#duration').html(totalFrames);
        currentFrame1 = obj.currentFrame;
        $('#current').html(currentFrame1);
        obj.addEventListener("onStateChange", "onytplayerStateChange");
    }
    swfobject.embedSWF(flashname, "myAlternativeContent", "800", "600", "9.0.0", false, flashvars, params, attributes, mycallback);
}

Bear in mind you may still encounter timing issues; SWFObject's callback is invoked as soon as the <object> is embedded in the page -- it doesn't mean the SWF has finished loading.

You can check the SWF's loading status by checking Flash Player's PercentLoaded method combined with a JavaScript setInterval.

var obj = event.ref;
if(obj.PercentLoaded() === 100){
    //do stuff
} else {
    //Use setInterval to check PercentLoaded again
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!