有很多人提示 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);
});
}
这就是我现在所拥有的。 Obv 不会做我们需要的。
还有其他的路可走吗?
最佳答案
您还可以查询 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);
关于javascript - 用于 SWF 加载时间的 SWFObject 加载计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7710799/