将变量从 HTML 传递到 Flash 影片

发布于 2024-07-30 17:47:12 字数 583 浏览 8 评论 0原文

作为一名 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 技术交流群。

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

发布评论

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

评论(2

瀞厅☆埖开 2024-08-06 17:47:12

您还可以使用ExternalInterface 来调用HTML 页面上返回值的JavaScript 函数。 这样做的附加值是您不必对值进行硬编码,并且可以将参数传递给 JavaScript 函数。

在 Flash 电影中:

import flash.external.ExternalInterface;

function getOutsideValue(argToJS:String):Void {
 var jsArgument:String = argToJS;
 var result:Object = ExternalInterface.call("stringAdd", jsArgument);
}

在 HTML 页面的 Javascript 中:

function stringAdd(inptStr){
 var strToAdd = inptStr;
 strToAdd += " added text";
 return strToAdd;
}

因此,当您在 Flash 中调用 ActionScript 函数时:

getOutsideValue("I get");

它将返回:

I get added text

请注意,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:

import flash.external.ExternalInterface;

function getOutsideValue(argToJS:String):Void {
 var jsArgument:String = argToJS;
 var result:Object = ExternalInterface.call("stringAdd", jsArgument);
}

In the Javascript in the HTML page:

function stringAdd(inptStr){
 var strToAdd = inptStr;
 strToAdd += " added text";
 return strToAdd;
}

So when you call the ActionScript function in Flash:

getOutsideValue("I get");

It will return:

I get added text

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.

等风也等你 2024-08-06 17:47:12

对我有用的答案是修改 CS4 生成的 HTML 中的 AC_FL_RunContent() 函数,添加需要传递给电影的参数,例如,

'flashvars', 'param=value',

这个函数似乎会覆盖 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.

'flashvars', 'param=value',

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文