2014-03-28 82 views
0

我試圖在我的HTML代碼中嵌入我的Flash遊戲。 我得到了嵌入正確的,但現在我想用GET來從URL 此獲得ID是url使用:HTML使用GET嵌入Flash SWFObject

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

我想使用嵌入代碼的URL 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); 

我究竟做錯了什麼?

回答

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

我發現,如果我取代 flashvars.id =「3」; 與 flashvars.id = getURLParameter('id'); 然後變量的設置工作。 和其他一切。 就這麼簡單,我不知道那個haha –

+0

getURLParameter()從何而來?這是一個SWFObject方法嗎? –

相關問題