HTML使用GET嵌入Flash SWFObject

时间:2014-03-28 11:58:59

标签: html flash get swfobject

我正在尝试将我的Flash游戏嵌入到我的HTML代码中。 我得到了嵌入权限,但现在我想使用GET从URL获取ID 这是我使用的网址:

http://localhost/directory/html/indexpage.php?id=3

我想使用嵌入代码获取网址的ID:

<head>
    <title> Widget </title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script type="text/javascript" src="scripts/swfobject.js"></script>
    <script type="text/javascript">
        var flashvars = {};
        flashvars.id = "3";

        var params = {};
        params.menu = "false";
        params.scale = "noscale";
        params.allowfullscreen = "false";

        var attributes = {};

        swfobject.embedSWF("flash/Flash.swf, "game", "398", "398", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
    </script>

    <link href="./mobile/styles/game.css" rel="stylesheet" type="text/css" media="screen" title="stylesheet" />
</head>

我试过了:

swfobject.embedSWF("flash/Flash.swf?id=3", "game", "398", "398", "9.0.0", "expressInstall.swf", flashvars, params, attributes);

我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

Flash没有解析查询字符串,可能是有充分理由的。你需要传入flashvars。这是一个常见的烦恼 - 也许SWFObject自从我上次不得不做这件事以来已经有所改进(2012),但如果没有,我倾向于拥有这样的代码:

function parseQueryString() {
    var query = window.location.search.substring(1);
    var keyVals = query.split("&")
    var dict = {}
    for (var i=0; i<keyVals.length; i++)
    {
        var pair = keyVals[i].split("=");
        dict[pair[0]] = unescape(pair[1]);
    }
    return dict;
}
...

flashvars = parseQueryString(); // catchall
flashvars.foo = parsedQuery.foo; // more explicit is probably better
...
swfobject.embedSWF(
    "MyFlashThing.swf", "flashContent", 
    "800", "600", 
    swfVersionStr, xiSwfUrlStr, 
    flashvars, params, attributes);