在SWFObject上加载计时器以获取SWF加载时间

wax*_*cal 1 javascript swfobject load-time

有很多人抱怨SWF上的加载时间很慢,但这样看起来很好.

我想在SWFObject javascript中添加一个加载计时器来计算加载SWF所需的时间,然后将其发送给我们(我将通过AJAX执行此操作).

我已经研究了使用SWFObject回调的可能性,它每10毫秒启动一个计时器,然后一旦成功就会停止.但是,看看这个,如果嵌入成功,而不是加载,这只是一个开关.

    function loadSWF(playURL){
      swfobject.embedSWF(playURL, "playdiv", "170", "90", "9.0.0", "expressInstall.swf", color:face00}, {wmode:"opaque",allowfullscreen:"true",allowScriptAccess:"always"}, '', function(e) { 

        var loadTimer = window.setInterval(function() {

            if(e.success) {

                milSeconds = milSeconds+10;
                clearInterval(loadTimer); alert('TIME ' + milSeconds);
            } else {

                milSeconds = milSeconds+10;

            }
        },10);          


    });
    }
Run Code Online (Sandbox Code Playgroud)

这就是我现在所拥有的.Obv不会做我们需要的.

还有其他人可以效仿吗?

pip*_*rks 5

您还可以查询SWF的PercentLoaded属性,而无需向SWF本身添加任何代码.这是一种快速(但草率)的方法:

var start_time, end_time, total_time;

function getCurrentTime(){ return new Date(); }

function checkSWFStatus(swf){
    if(swf.PercentLoaded() !== 100){
        setTimeout(function (){
            checkSWFStatus(swf);
        }, 50);
    } else {
        end_time = getCurrentTime();
        total_time = end_time-start_time;
        console.log("Ended: " +end_time);
        console.log("Total load time: approximately " +total_time +" milliseconds");
    }
}

var callback = function (e){

    if(e.success && e.ref){

        if(!start_time){
            start_time = getCurrentTime();
            console.log("Started: " +start_time);
        }

        //Ensure SWF is ready to be polled
        setTimeout(function checkSWFExistence(){
            if(typeof e.ref.PercentLoaded !== "undefined"){
                checkSWFStatus(e.ref);
            } else {
                checkSWFExistence();
            }
        }, 10);

    }

};

swfobject.embedSWF("yourmovie.swf", "targetelement", "550", "400", "9", false, false, false, false, callback);
Run Code Online (Sandbox Code Playgroud)