2011-11-03 55 views
1

我得到這個錯誤 「Microsoft JScript運行錯誤:」SWFObject的未定義「JavaScript的不工作SWFObject的是未定義

我的代碼看起來像這樣

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script> 
    <div id="flashcontent">This text is replaced by the Flash movie. </div> 
<script type="text/javascript"> 
    var rndPick = 2; 
    var rndPick = Math.floor(Math.random() * 16) + 1; 
    var movie = "/Flash/sam" + rndPick + ".swf"; 
    var so = new SWFObject(movie, "mymovie", "955", "170", "8", "#336699"); 
    so.write("flashcontent"); 
    setTimeout("location.reload(true);", 14500); 
</script> 

回答

4

你使用SWFObject 1.5語法,但鏈接到SWFObject 2.2 JS文件。 SWFObject 1.5和2.2不兼容。

重寫您的SWFObject代碼以使用2.2語法。這裏是你的代碼轉換爲SWFObject 2.2語法。請注意,當DOM完成加載時,swfobject.embedSWF會自動執行。

<head> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script> 

<script type="text/javascript"> 
var rndPick = Math.floor(Math.random() * 16) + 1; 
var movie = "/Flash/sam" + rndPick + ".swf"; 

var flashvars = {}; //empty for this example 
var params = { bgcolor: "#336699" }; //sets background color 
var attributes = { id: "mymovie" }; //sets ID of <object> to "mymovie" 

//Optional callback function gets executed after <object> is created 
var callbackFn = function(){ 
    setTimeout("location.reload(true);", 14500); 
}; 

swfobject.embedSWF(movie, "flashcontent", "955", "170", "8", false, flashvars, params, attributes, callbackFn); 

</script> 
</head> 

<body> 
    <div id="flashcontent">This text is replaced by the Flash movie. </div> 
</body> 
+0

謝謝,就是這樣,我還沒有看到任何關於SWFObject 1.5和2.2不兼容的話題。 – StephanM