AS3 将 FlashVars 传递给加载的 swf
我有一个 A.swf,它将 B.swf 加载到影片剪辑上,并且需要向其传递一些 FlashVars。当用html加载B.swf时,我可以很好地传递FlashVars。从 A.swf 传递时,它会收到
错误 #2044: Unhandled ioError:。 text=错误#2032:流错误。 URL: file:
A.swf 中的代码
var request:URLRequest = new URLRequest ("B.swf");
var variables : URLVariables = new URLVariables();
variables.xml = "test.xml";
// This line causes the error 2044, else B.swf loads fine with FlashVars
request.data = variables;
loader.load (request);
在 B.swf 中,它像这样检查 Flashvars。从 html 端看它工作得很好
this.loaderInfo.parameters.xml
I have a A.swf which loads B.swf onto a movieclip and needs to pass it some FlashVars. When loading B.swf with html, I can pass FlashVars fine. When passing from A.swf, it gets a
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:
The code in A.swf is
var request:URLRequest = new URLRequest ("B.swf");
var variables : URLVariables = new URLVariables();
variables.xml = "test.xml";
// This line causes the error 2044, else B.swf loads fine with FlashVars
request.data = variables;
loader.load (request);
In B.swf, it is checking the Flashvars like so. It works fine from html side
this.loaderInfo.parameters.xml
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尽管 querystring 方法在本地应该可以正常工作,但如果您使用的是 Flash Player 10.2,则有一个新的 API 可以实现此目的。
文档在这里:
http://help.adobe.com /en_US/FlashPlatform/reference/actionscript/3/flash/system/LoaderContext.html#parameters
Although the querystring method should work fine locally, if you're using Flash Player 10.2, there's a new API for this.
The documentation is here:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/LoaderContext.html#parameters
“A”不必将 FlashVars 传递给“B”。只需让 B 访问 FlashVars 本身即可。无论 B 位于 A 内部还是位于顶层本身,以下操作都将起作用:
在 B 的构造函数中添加 ADDED_TO_STAGE 事件侦听器。例如:
当您有权访问舞台时,您现在可以通过以下方式访问 A 中的 FlashVars:
要正确查看 B.swf 中名为
myVar
flashVar 的变量,您可以(在 B 内)执行:stage.loaderInfo 是您需要查看的内容。
It's not necessary that "A" pass FlashVars to "B". Just have B access the FlashVars itself. The following will work whether B is inside of A, or top-level itself:
Add an ADDED_TO_STAGE event listener in B's constructor. e.g.:
When you have access to the stage you can now access the FlashVars in A this way:
To properly see a variable called
myVar
flashVar in B.swf, you do (inside B):stage.loaderInfo
is what you need to look at.你可以在加载时将 flash 变量添加到 URI 中,但
问题是,当你加载 uri 中的字符串时,它会被放入一个对象
loaderInfo.parameters
中,所以如果你想传递这些参数,您需要创建一个字符串来传递这些参数。这是来自 http://ragona.com/blog/pass-flashvars-loaded 的脚本-swf/ 显示如何将其再次转换为字符串数组
you can add the flash vars into the URI when you are loading it
the problem is that when you loaded the string in the uri, it is put inside an Object
loaderInfo.parameters
so if you want to pass those parameters, you need to create a string to pass these into.here's a script from http://ragona.com/blog/pass-flashvars-loaded-swf/ that shows how to convert that into a string array again
如何沙箱权限?我尝试通过设置添加文件夹,但这也不起作用。
http://www.macromedia.com/support/ Documentation/en/flashplayer/help/settings_manager04.html#117502
我做了一个简单的新项目。这是完整的代码。
How do I sandbox the permissions? I tried adding the folder via the settings, but that didn't work too.
http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html#117502
I made a simple as new project. This is the complete code.