问题
Having a number of people complaining of slow load times on an SWF, but it appears fine this end.
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).
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);
});
}
That's what I have right now. Obv won't do what we need.
Has anyone another path to follow?
回答1:
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);
回答2:
For those who are interested; the only way to resolve this was to get flash to make a call with:
ExternalInterface.call("some_js_function()", "the-argument");
The some_js_function() can then stop the timer I set running when the page loaded.
来源:https://stackoverflow.com/questions/7710799/load-timer-on-swfobject-for-swf-load-time