2011-09-26 35 views
0

我有一個1.2MB的Flash SWF。 正在使用swfobject嵌入它使用動態嵌入。swfobject閱讀flashvars問題

<script type="text/javascript"> 
var flashvars = {}; 

flashvars.campaignid = "12345678890"; 
var params = {}; 
params.allowscriptaccess = "always"; 
var attributes = {}; 
swfobject.embedSWF("soccer.swf", "myAlternativeContent", "550", "400", "10.0.0", false, flashvars, params, attributes); 
</script> 

上午特林閱讀我的文檔類裏面CAMPAIGNID ...

代碼如下

public function Main() 
{  
    loaderInfo.addEventListener(ProgressEvent.PROGRESS,update); 
    loaderInfo.addEventListener(Event.COMPLETE,onLoadedMovie); 
}     
private function update(e:ProgressEvent):void   
{ 
} 

private function onLoadedMovie(e:Event) 
{ 
    campId=this.root.loaderInfo.parameters["campaignid"]; 
} 

當我當我用同樣的方法提醒我得到空 值一個小文件的作品.. 任何人都可以幫助我嗎? 關於

+0

是否「當我警告值「意味着當您使用'alert()'javascript或'trace()'時使用actionscript。另外當我在一個小文件中使用同樣的方法時,它是什麼意思?什麼小文件? – Taurayi

+0

警報是第三方課程,在閃光燈中進行警示。 小文件意味着大小,約爲1.6 MB。但事情是我用1.8 MB的文件創建了另一個文件,並且swf讀取了參數。 其實我找到了答案。我只是在嵌入代碼中添加變量,如 swfobject.embedSWF(「soccer.swf?campaignid = 1234556」) – harilalkm

回答

2

我通過在嵌入代碼中添加變量得到答案。這樣

swfobject.embedSWF("soccer.swf?campaignid=1234556"", "myAlternativeContent", "550", "400", "10.0.0", false, flashvars, params, attributes); 

感謝您的幫助:)

0

也許嘗試讓您的Main類添加到舞臺後獲取var。這將確保一切都已加載並準備就緒。嘗試這樣的:

public function Main() 
{ 
    if (stage) init(); 
    else addEventListener(Event.ADDED_TO_STAGE, init); 
} 

private function init(e:Event = null):void 
{ 
    removeEventListener(Event.ADDED_TO_STAGE, init); 

    var campId:String = this.root.loaderInfo.parameters["campaignid"]; 
    trace('campId', campId); 
} 
+0

我已經更改了嵌入代碼,它似乎正在工作。 swfobject.embedSWF(「soccer.swf?campaignid = 1234556」, 我不知道原因,但我得到了閃光燈內的價值 – harilalkm

+0

您的代碼不爲我操作:( – harilalkm

1

亞當·哈特的答案是正確的,我認爲問題的關鍵在於你的AS3代碼中的某處,以下特別是搞糊塗了:

public function Main() 
{  
    loaderInfo.addEventListener(ProgressEvent.PROGRESS,update); 
    loaderInfo.addEventListener(Event.COMPLETE,onLoadedMovie); 
} 

private function update(e:ProgressEvent):void { } 

private function onLoadedMovie(e:Event) 
{ 
    campId=this.root.loaderInfo.parameters["campaignid"]; 
} 

我已經創建了一個簡單(和工作)的例子,說明你的代碼應該如何看待:

index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>FlashVars</title> 
    <meta name="language" content="en" /> 
    <meta name="description" content="" /> 
    <meta name="keywords" content="" /> 
    <script src="js/swfobject.js" type="text/javascript"></script> 
    <script type="text/javascript"> 
     var flashvars = { campaignid: "12345678890" }; 
     var params = { menu: "false", scale: "noScale", allowFullscreen: "true", allowScriptAccess: "always", bgcolor: "", wmode: "direct" }; 
     var attributes = { id:"FlashVars" }; 
     swfobject.embedSWF("FlashVars.swf", "altContent", "100%", "100%", "10.0.0", "expressInstall.swf", flashvars, params, attributes); 
    </script> 
    <style type="text/css"> 
     html, body { height:100%; overflow:hidden; } 
     body { margin:0; } 
    </style> 
</head> 
<body> 
    <div id="altContent"> 
     <h1>FlashVars</h1> 
     <p>Alternative content</p> 
     <p> 
      <a href="http://www.adobe.com/go/getflashplayer"> 
       <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /> 
      </a> 
     </p> 
    </div> 
</body> 
</html> 

Main.as(文檔類):

package 
{ 
    import flash.display.Sprite; 
    import flash.events.Event; 
    import flash.text.TextField; 
    import flash.text.TextFieldAutoSize; 

    public class Main extends Sprite 
    { 
     public function Main():void 
     { 
      if (stage) init(); 
      else addEventListener(Event.ADDED_TO_STAGE, init); 
     }// end function 

     private function init(e:Event = null):void 
     { 
      removeEventListener(Event.ADDED_TO_STAGE, init); 

      if (loaderInfo.parameters.campaignid) 
      { 
       var textField:TextField = new TextField(); 
       textField.autoSize = TextFieldAutoSize.LEFT; 
       textField.text = loaderInfo.parameters.campaignid; 
       addChild(textField); 

      }// end if 

     }// end function 

    }// end class 

}// end package 

下面是示例在瀏覽器中運行beening的圖像:

enter image description here