有很多人抱怨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不会做我们需要的。
还有其他人可以关注吗?
答案 0 :(得分: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);
答案 1 :(得分:0)
对于那些感兴趣的人;解决这个问题的唯一方法是让闪电用以下方式拨打电话:
ExternalInterface.call("some_js_function()", "the-argument");
some_js_function()可以在页面加载时停止我设置的计时器。