尝试在没有警报的情况下运行以下代码(“”); 通过警报,它可以正常工作,没有警报失败。
任何人都知道为什么?
$(document).ready(function () {
var flashvars = {};
var params = {};
var attributes = {};
var embedHandler = function (e){
if(e.success){
alert('without this it fails')
var f = swfobject.getObjectById('gameplayer');
f.tabIndex = 0;
f.focus();
} else {
//failed
}
};
swfobject.embedSWF("/assets/gameplayer2.swf", "gameplayer", "393", "400", "9.0.0", "flash/expressInstall.swf", flashvars, params, attributes, embedHandler );
});
答案 0 :(得分:0)
根据您的alert
与您的SWFObject嵌入语句(swfobject.getObjectById('record')
)中的ID不匹配,无论"gameplayer"
是什么,都不确定代码为什么会起作用。< / p>
他们需要匹配。您可以将swfobject.getObjectById('record')
更改为swfobject.getObjectById('gameplayer')
,也可以将var params = {};
更改为var params = { id: 'record' };
,以确保新<object>
的ID为"record"
。
您可以在此处详细了解参数选项:http://learnswfobject.com/the-basics/advanced-options-with-dynamic-publishing/
更新了更新问题的答案
这可能是一个时间问题; e.success
仅表示<object>
已成功写入页面,而不是Flash Player已完成初始化和/或SWF已完成加载。
尝试轮询SWF以查看PercentLoaded
是否已完成加载,然后执行您的代码。
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", "9", false, false, false, false, callback);
从http://learnswfobject.com/advanced-topics/executing-javascript-when-the-swf-has-finished-loading/
复制的代码