在某些情况下,它可能就像检查嵌入是否成功一样简单。这可以通过 SWFObject 的createSWF
方法同步完成。
swfobject.customEmbed = function (swfLoc, id, w, h, version, color){
if (swfobject.hasFlashPlayerVersion(version)){
var so = swfobject.createSWF({data:swfLoc,width:w,height:h}, {bgcolor:color},id);
//swfobject.createSWF returns an HTML element, not a boolean
if(so){ return true; }
}
return false;
}
var success = swfobject.customEmbed("mymovie.swf", "flashcontent", "550", "400", "10", "#FFF");
if(!success){
//embed failed! do something appropriate
}
警告:当 SWFObject 告诉您是否embed
成功时,它具体指的是是否创建了新的 HTML 标记,而不是 SWF 是否已实际加载(例如,SWFObject 会告诉您它是成功的,即使 SWF 是 404'd) .
确定 SWF 是否实际加载的唯一方法是轮询 SWF 以获取加载百分比:
function swfLoadEvent(fn){
//Ensure fn is a valid function
if(typeof fn !== "function"){ return false; }
//This timeout ensures we don't try to access PercentLoaded too soon
var initialTimeout = setTimeout(function (){
//Ensure Flash Player's PercentLoaded method is available and returns a value
if(typeof e.ref.PercentLoaded !== "undefined" && e.ref.PercentLoaded()){
//Set up a timer to periodically check value of PercentLoaded
var loadCheckInterval = setInterval(function (){
//Once value == 100 (fully loaded) we can do whatever we want
if(e.ref.PercentLoaded() === 100){
//Execute function
fn();
//Clear timer
clearInterval(loadCheckInterval);
}
}, 1500);
}
}, 200);
}
//This function is invoked by SWFObject once the <object> has been created
var callback = function (e){
//Only execute if SWFObject embed was successful
if(!e.success || !e.ref){ return false; }
swfLoadEvent(function(){
//Put your code here
alert("The SWF has finished loading!");
});
};
swfobject.embedSWF("movie.swf", "flashcontent", "550", "400", "10", false, false, false, false, callback);
如果这些方法中的任何一种对您有用,请回复,我很好奇结果。谢谢