2012-12-04 57 views
0

以下代碼在同一個div中一次加載3個swf文件。 我如何跟蹤哪些瑞士法郎加載在特定的時間在PHP或JavaScript b'se我想使用IF語句的地方像if($ i == 1)其中$ i是一個變量等於一時1.swf加載&當2.swf加載時,$ i == 2。跟蹤哪個隨機swf加載

  function loadFlash(){ 

       function getRandomFilename() 
       { 
        var names = [ 
         '1.swf', 
         '2.swf', 
         '3.swf' 
        ]; 
        var r = Math.floor(Math.random() * names.length); 
        return names[r]; 
       } 

       var flashvars = {}; 
       var params = {wmode:"opaque"}; 
       var attributes = {}; 
       swfobject.embedSWF(getRandomFilename(), "SWF_Output", "900", "120", "8.0.0", false, flashvars, params, attributes); 

      } 

暴民...在此先感謝

+0

很酷,明白了。名稱[R];變量存儲在任何給定時間加載的swf的路徑 – Mwesigwa

回答

0

編輯你的代碼是這樣的:

function loadFlash(){ 
    function getRandomFilename() { 
     var names = [ 
      '1.swf', 
      '2.swf', 
      '3.swf' 
     ]; 
     var r = Math.floor(Math.random() * names.length); 
     return [names[r], r]; 
    } 

    var flashvars = {}; 
    var params = {wmode:"opaque"}; 
    var attributes = {}; 
    var file = getRandomFilename(); 
    swfobject.embedSWF(file[0], "SWF_Output", "900", "120", "8.0.0", false, flashvars, params, attributes); 
    //file[0] will be the file name ('1.swf' - '3.swf') 
    //file[1] will be the array index (0 - 2) 
} 

您將無法訪問names[r]getRandomFilename功能(out of scope

+0

Thx Cerbrus,使生活更輕鬆。 – Mwesigwa

+0

如果是您的解決方案,您會考慮[將此標記爲答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)嗎? – Cerbrus