从子加载的 swf 访问 HTML 中定义的 flashvar?答案如下

发布于 2024-10-02 01:47:24 字数 1461 浏览 0 评论 0原文

我的 html 文件中存储了一个 flash var:

<script type="text/javascript">

    var flashvars = {

        map:"mapGAcentury21.xml"

    };

    var params = {

        menu: "false",

        scale: "noScale",

        allowFullscreen: "true",

        allowScriptAccess: "always",

        bgcolor: "#FFFFFF"

    };

    var attributes = {

        id:"REMap"

    };

    swfobject.embedSWF("REMap.swf", "altContent", "840", "630", "9.0.0", "expressInstall.swf", flashvars, params, attributes);

</script>

我有一个在 FlashDevelop 中开发的 flash 应用程序。我从这个 Flash 应用程序中加载一个名为 728x90.swf 的文件。我可以自由编辑我的 728x90.fla 文件,但我不想更改我的主 Flash 应用程序文件。

如何从 728x90.swf 文件中访问 flashvars 变量?

编辑:

The following codes traced "your variable is undefined" 
1. trace("your variable is " + stage.loaderInfo.parameters.flashvars); 
2. trace("your variable is " + loaderInfo.parameters.flashvars); 
3. trace("your variable is " + loaderInfo.parameters.flashvars.map);
4. trace("your variable is " + stage.loaderInfo.parameters.flashvars.map);

编辑2: 我将整个 javascript 代码粘贴到我原来的帖子中。我的 flashvars 被传递到名为“REMap.swf”的主 swf 文件中 REMap.swf

public var requestAd:URLRequest = new URLRequest("media/728x90.swf");

然后在函数中,以下代码加载我的 728x90.swf 文件

loaderAd.load(requestAd);
addChild(loaderAd);
loaderAd.contentLoaderInfo.addEventListener(Event.COMPLETE, promoLoaded);

I have a flash var stored in my html file:

<script type="text/javascript">

    var flashvars = {

        map:"mapGAcentury21.xml"

    };

    var params = {

        menu: "false",

        scale: "noScale",

        allowFullscreen: "true",

        allowScriptAccess: "always",

        bgcolor: "#FFFFFF"

    };

    var attributes = {

        id:"REMap"

    };

    swfobject.embedSWF("REMap.swf", "altContent", "840", "630", "9.0.0", "expressInstall.swf", flashvars, params, attributes);

</script>

I have a flash application I developed in FlashDevelop. From within this Flash application I load a file called 728x90.swf. I can freely edit my 728x90.fla file but I do not want to change my main flash application files.

How can I access the flashvars variable from within my 728x90.swf file?

EDIT:

The following codes traced "your variable is undefined" 
1. trace("your variable is " + stage.loaderInfo.parameters.flashvars); 
2. trace("your variable is " + loaderInfo.parameters.flashvars); 
3. trace("your variable is " + loaderInfo.parameters.flashvars.map);
4. trace("your variable is " + stage.loaderInfo.parameters.flashvars.map);

EDIT 2:
I pasted my entire javascript code into my original post. my flashvars are being passed into my main swf file called "REMap.swf" The REMap.swf

public var requestAd:URLRequest = new URLRequest("media/728x90.swf");

Then in a function the following code loads my 728x90.swf file

loaderAd.load(requestAd);
addChild(loaderAd);
loaderAd.contentLoaderInfo.addEventListener(Event.COMPLETE, promoLoaded);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

删除→记忆 2024-10-09 01:47:24

您可以通过调用获取父swf的参数

parent.loaderInfo.parameters

You can get the parameters of the parent swf by calling

parent.loaderInfo.parameters
ぺ禁宫浮华殁 2024-10-09 01:47:24

您的文档对象是一个MovieClip。与 MovieClip 关联的 flashvar 存储在其 loaderInfo.parameters 属性中。不要从 stage.loaderInfo.parameters 获取 flashvars,除非您希望 flashvars 与原始调用 flash 影片关联。

编辑添加:

了解如何将 flashvars 传递到 Flash 视频。我感觉您正在尝试从 Flash 访问 JavaScript 对象。这也可以完成,您只需要阅读 flash.external.ExternalInterface

编辑#2:

public var requestAd:URLRequest = new URLRequest("media/728x90.swf");

可能应该是:

public var requestAd:URLRequest = new URLRequest("media/728x90.swf?map=mapGAcentury12.xml");

检查 swfobject.embedSWF 调用生成的 HTML。它可能无法正确发送 flashvars。

Your document object is a MovieClip. The flashvars associated with the MovieClip are stored in its loaderInfo.parameters property. Don't get the flashvars from stage.loaderInfo.parameters unless you want the flashvars associated with the original calling flash movie.

Edit to add:

Read about how to pass flashvars to a flash video. I'm getting the feeling that you're trying to access a JavaScript object from flash. That can be done too, you'll just need to read up on flash.external.ExternalInterface

Edit #2:

public var requestAd:URLRequest = new URLRequest("media/728x90.swf");

should probably be:

public var requestAd:URLRequest = new URLRequest("media/728x90.swf?map=mapGAcentury12.xml");

Check out what HTML is generated by the swfobject.embedSWF call. It might not be sending the flashvars correctly.

随心而道 2024-10-09 01:47:24

简单的答案:

创建一个变量并将其命名为您想要的任何名称。我尝试了以下三个:

var s1:String = stage.loaderInfo.parameters["map"];
var s2:String = this.root.loaderInfo.parameters["map"];
var s3:String = root.loaderInfo.parameters.map;

trace(s1 + " " + s2 + " " + s3);

输出:mapGA century21.xml null null

答案:
为了从子 swf 访问父 swf 的 flashvars,请使用以下代码:

var s1:String = stage.loaderInfo.parameters["PLACE THE NAME OF YOUR FLASHVAR WITHIN QUOTATIONS"];
trace(s1);

Simple answer:

Create a variable and name it whatever you want. I tried the following three:

var s1:String = stage.loaderInfo.parameters["map"];
var s2:String = this.root.loaderInfo.parameters["map"];
var s3:String = root.loaderInfo.parameters.map;

trace(s1 + " " + s2 + " " + s3);

The output: mapGAcentury21.xml null null

Answer:
In order to access flashvars of a parent swf from a child swf use the following code:

var s1:String = stage.loaderInfo.parameters["PLACE THE NAME OF YOUR FLASHVAR WITHIN QUOTATIONS"];
trace(s1);
如果没有你 2024-10-09 01:47:24

Phil 的说法是正确的:

var s1:String = stage.loaderInfo.parameters["map"];

可以工作,但是在子 SWF 已添加到舞台时才工作。加载完成后,这种情况会发生在一个/某些帧上。
您可以像这样监听子进程中的事件:

public function instantiateChildClass(){
   trace(stage.loaderInfo.parameters["map"]); //throws error if this SWF has just been loaded into a parent SWF
   addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event):void{
   removeEventListener(Event.ADDED_TO_STAGE, init);
   trace(stage.loaderInfo.parameters["map"]); //traces map param
}

Phil is correct that:

var s1:String = stage.loaderInfo.parameters["map"];

will work, but it will only work if the child SWF has already been added to the stage. This happens one/some frame(s?) after loading is complete.
You can listen the the event in the child like so:

public function instantiateChildClass(){
   trace(stage.loaderInfo.parameters["map"]); //throws error if this SWF has just been loaded into a parent SWF
   addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event):void{
   removeEventListener(Event.ADDED_TO_STAGE, init);
   trace(stage.loaderInfo.parameters["map"]); //traces map param
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文