2010-06-24 55 views
0

我使用的是舊版本SWFObject.js的其中嵌入了一個SWF到HTML這樣的遺留代碼:如何遷移SWFObject調用代碼?

var so = new SWFObject("main.swf", "main", "100%", "615", "9.0.115", "#000000"); 
so.addVariable("deeplink", deeplink); 
so.addVariable("cid", cid); 
so.addParam("scaleMode", "noscale"); 
so.addParam("allowScriptAccess", "always"); 
so.addParam("allowFullScreen", "true"); 
so.write("flashcontent"); 

我應該如何重寫最新SWFObject.js?我已經嘗試過,但失敗了,我想首先排除語法不匹配:

var mainSwfProperties = { 
    flashVars : { 
     cid : cid, 
     deeplink : deeplink 
    }, 
    params : { 
     allowFullScreen : "true", 
     allowScriptAccess : "true", 
     scaleMode : "noscale", 
     wmode : "window" 
    }, 
    attributes : {} 
}; 
swfobject.embedSWF("main.swf", "flashcontent", "100%", 615, "9.0.115", null, 
    mainSwfProperties.flashVars, 
    mainSwfProperties.params, 
    mainSwfProperties.attributes 
); 

回答

1

那麼,我一定會認爲這會起作用。基本上,flashvars,params和屬性需要是js對象。我通常把它們作爲單獨的對象,而不是像你設置的那樣有一個單獨的對象。

<script type="text/javascript"> 
    var flashvars = {cid:cid, deeplink:deeplink}; 
    var params = {allowFullScreen:true, allowScriptAccess:true, scaleMode:"noscale", wmode:"window"}; 
    var attributes = {} 
    swfobject.embedSWF("main.swf", "flashcontent", "100%", "615", "9.0.115", null, flashvars, params, attributes); 
</script> 
0

同樣來自swfobject文檔,它期望寬度和高度是字符串,你有高度作爲int在那裏。

+0

SWFObject 2.3 beta修復了此https://github.com/swfobject/swfobject – pipwerks 2013-01-04 17:59:09