在SWFObject上加载计时器以获取SWF加载时间 [英] Load timer on SWFObject for SWF load time
问题描述
有很多人抱怨SWF上的加载时间很慢,但是这个结果看起来很好。
Having a number of people complaining of slow load times on an SWF, but it appears fine this end.
我想添加一个加载计时器SWFObject javascript用于计算加载SWF然后将其发送回给我们需要多长时间(我将通过AJAX执行此操作)。
I'd like to add a load timer in the SWFObject javascript to time how long it takes to load an SWF and then send it back to us (I'll do that via AJAX).
我调查了可能性使用SWFObject回调,每10个小时启动一个计时器,然后一旦成功就会停止。但是,看看这个,如果嵌入成功,而不是加载,这只是一个开关。
I've looked into possibles with SWFObject callback, which starts a timer every 10millisecodns and then will stop once success. But, looking at this, this is just a switch if embed has been successful, not load.
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不会做我们需要的。
That's what I have right now. Obv won't do what we need.
还有其他人可以关注吗?
Has anyone another path to follow?
推荐答案
您还可以查询SWF的 PercentLoaded
属性,而无需向SWF本身添加任何代码。这是一种快速(但草率)的方法:
You can also query the SWF's PercentLoaded
property without needing to add any code to the SWF itself. Here's a quick (but sloppy) way to do it:
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);
这篇关于在SWFObject上加载计时器以获取SWF加载时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!