【发布时间】:2011-09-30 17:41:32
【问题描述】:
我有一个使用 SWFobject 嵌入 Flash 播放器的 javascript 脚本。当我用
嵌入 Flash 播放器时swfobject.embedSWF(..)
我读到 swfobject 未定义的错误。我相信这是因为我们的网站缓存了我的应用程序的 javascript,但没有缓存 swfobject.js 文件,所以调用 swfobject.embedSWF(..) 的 myApp.js 早在 swfobject.js 之前就加载了。我目前无法更改正在缓存的内容,所以我想出了这个解决方法:
while(!$(that.mediaPlayer).find('#'+that.playerID)[0]){
console.log(that.playerID+' not defined');
that.embedFlashPlayer(1,1);
}
...
this.embedFlashPlayer = function (width, height){
var that = this;
var playerID = that.playerID;
var server = document.URL.replace(/^.*\/\//,'').replace(/\..*$/,'');
var flashvars = {};
var flashSrc = "/flash/AS3MediaPlayer.swf?server"+server+"&playerID="+playerID;
//parameters
var params = {};
params.movie = flashSrc;
params.quality = "high";
params.play = "true";
params.LOOP = "false";
params.wmode = "transparent";
//attributes
var attr = {};
attr.classid = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
attr.codebase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,16,0";
attr.width = "" + width;
attr.height = "" + height;
attr.id = playerID;
//console.log("embedding flash object with id "+playerID);
//command to embed flash object
try{
swfobject.embedSWF(flashSrc, "no-flash", width, height,"9.0.0","",flashvars,params);
}catch(err){
// I DON'T KNOW WHAT TO DO HERE
}
return true;
}
我的代码检查是否已写入 Flash 对象。如果没有,它会在 while 循环中重复调用 embed this.embedFlashPlayer() 直到找到包含 swf 的 div。麻烦的是,这只是永远循环。如果 swfobject 未定义,关于我可以在 try-catch 块中做什么的任何建议?我 90% 确定这是因为我的脚本加载速度更快,并且在库加载之前运行了 embedSwfObject 命令,但我可能错了。我的脚本在 $(function(){...}) 命令中运行。任何关于我如何解决这个问题的理论、建议和想法都将不胜感激。
【问题讨论】:
标签: javascript swfobject infinite-loop externalinterface