简体   繁体   中英

How to migrate SWFObject call code?

I have this legacy code which embeds an SWF into an HTML using an old version of SWFObject.js:

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");

How should I rewrite it for the latest SWFObject.js? I have tried this but failed, and I would like to rule out the syntax-mismatch first:

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
); 

Well, I would certainly think that would work. Basically, the flashvars, params, and attributes need to be js objects. I usually leave them as separate objects rather than having a single object like you have set uo.

<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>

同样从swfobject文档中,它希望width和height为字符串,而您将height作为一个int。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM