将变量从 HTML 传递到 Flash 影片
作为一名 Flash 新手,我发现这非常令人困惑,并且花了我几个小时。 在这里回答我自己的问题,以防有人遇到同样的问题。
从技术上讲,您应该能够执行以下操作:
<param name="movie" value="movie.swf?param=value" />
<embed src="movie.swf?param=value" ...
或者这样:
<PARAM NAME "FlashVars" VALUE="param=value">
<EMBED .... FlashVars="param=value">
两者都应该在 _root 或 _level0 范围中创建一个名为“param”且具有正确值的变量。
这些记录在此处
但是,在我特定的 Flash 版本(CS4、ActionScript 2.0),这不起作用。
As a Flash newbie I found this very confusing and it cost me a couple of hours. Answering my own question here in case anyone has the same problem.
Technically you should be able to do something like this:
<param name="movie" value="movie.swf?param=value" />
<embed src="movie.swf?param=value" ...
Or this:
<PARAM NAME "FlashVars" VALUE="param=value">
<EMBED .... FlashVars="param=value">
Both should create a variable in the _root or _level0 scope called 'param' with the correct value.
These are documented here
However, in my particular version of Flash (CS4, ActionScript 2.0), this didn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以使用ExternalInterface 来调用HTML 页面上返回值的JavaScript 函数。 这样做的附加值是您不必对值进行硬编码,并且可以将参数传递给 JavaScript 函数。
在 Flash 电影中:
在 HTML 页面的 Javascript 中:
因此,当您在 Flash 中调用 ActionScript 函数时:
它将返回:
请注意,ExternalInterface 也可用于从 JavaScript 调用 Flash 内部的函数。 两者的示例都可以在这里找到: http://kb2.adobe.com/cps/ 156/tn_15683.html
看来这是在 SWF 电影之间传递信息的推荐方式,它肯定比仅使用硬编码值更加动态和强大。
You could also use ExternalInterface to call a JavaScript function on the HTML page that returns a value. This has the added value that you don't have to hardcode the value and you can pass parameters to the JavaScript function.
In the Flash Movie:
In the Javascript in the HTML page:
So when you call the ActionScript function in Flash:
It will return:
Note that ExternalInterface can also be used to call functions inside the Flash from JavaScript. Examples of both can be found here: http://kb2.adobe.com/cps/156/tn_15683.html
It seems that this is the recommended way to passing information to and from SWF movies, it certainly is more dynamic and powerful than just using hard coded values.
对我有用的答案是修改 CS4 生成的 HTML 中的 AC_FL_RunContent() 函数,添加需要传递给电影的参数,例如,
这个函数似乎会覆盖 OBJECT 和 EMBED 标签中直接指定的任何内容或在查询字符串上。
那里可能有更好的解决方案......
The answer which worked for me is to modify the AC_FL_RunContent() function in the HTML generated by CS4, adding the parameters which need to be passed to the movie, e.g.
It seems this function overwrites anything which is directly specified in the OBJECT and EMBED tags or on the query string.
There may be better solutions out there...