从子加载的 swf 访问 HTML 中定义的 flashvar?答案如下
我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以通过调用获取父swf的参数
You can get the parameters of the parent swf by calling
您的文档对象是一个MovieClip。与 MovieClip 关联的 flashvar 存储在其 loaderInfo.parameters 属性中。不要从
stage.loaderInfo.parameters
获取 flashvars,除非您希望 flashvars 与原始调用 flash 影片关联。编辑添加:
了解如何将 flashvars 传递到 Flash 视频。我感觉您正在尝试从 Flash 访问 JavaScript 对象。这也可以完成,您只需要阅读 flash.external.ExternalInterface
编辑#2:
可能应该是:
检查
swfobject.embedSWF
调用生成的 HTML。它可能无法正确发送 flashvars。Your document object is a
MovieClip
. The flashvars associated with the MovieClip are stored in itsloaderInfo.parameters
property. Don't get the flashvars fromstage.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:
should probably be:
Check out what HTML is generated by the
swfobject.embedSWF
call. It might not be sending the flashvars correctly.简单的答案:
创建一个变量并将其命名为您想要的任何名称。我尝试了以下三个:
输出:mapGA century21.xml null null
答案:
为了从子 swf 访问父 swf 的 flashvars,请使用以下代码:
Simple answer:
Create a variable and name it whatever you want. I tried the following three:
The output: mapGAcentury21.xml null null
Answer:
In order to access flashvars of a parent swf from a child swf use the following code:
Phil 的说法是正确的:
可以工作,但是它仅在子 SWF 已添加到舞台时才工作。加载完成后,这种情况会发生在一个/某些帧上。
您可以像这样监听子进程中的事件:
Phil is correct that:
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: