我有一个1.2mb的闪光swf。 我使用动态嵌入将其与swfobject一起嵌入。
<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"];
}
当我提醒值时,我得到了null 当我在一个小文件中使用相同的方法时,它的工作原理.. 谁能帮我? 问候
答案 0 :(得分:2)
我通过在嵌入代码中添加变量得到了答案。像这样
swfobject.embedSWF("soccer.swf?campaignid=1234556"", "myAlternativeContent", "550", "400", "10.0.0", false, flashvars, params, attributes);
感谢您的帮助:)
答案 1 :(得分:1)
Adam Harte的回答是正确的,我认为问题出在你的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
以下是在浏览器中运行的示例的图像:
答案 2 :(得分: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);
}