html - AS3 - 将变量数据从 HTML 页面传递到 flash

标签 html actionscript-3 flash

我有一个 SWF 文件形式的音乐播放器,我需要帮助转换我的静态 AS3 源路径:

var url :URLRequest = new URLRequest("images/logo.jpg");
var req:URLRequest = new URLRequest("click.mp3");

...进入可以从 HTML 页面传入的参数。我想做这样的事情:

<object width="480" height="270" data="soundplayer.swf" sound="click.mp3" image="logo.jpg"></object>`

我想要的最终结果是在 HTML 代码中指定声音和图像路径,而不是在我的 SWF 文件中硬编码。

最佳答案

您可以使用 FlashVars 来完成此操作

您添加 <param>对象标记中名称为 FlashVars 的节点并且该值应该是 url 编码的查询字符串变量。

所以你的场景,这将是你的对象标签的开始:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="270">
    <param name="movie" value="soundplayer.swf" />
    <param name="FlashVars" value="sound=click.mp3&image=logo.jpg" />

然后在 AS3 中,您可以按如下方式访问它们:

var flashVars:Object = LoaderInfo(this.root.loaderInfo).parameters;

var url:URLRequest = new URLRequest("images/" + flashVars.image);
var req:URLRequest = new URLRequest(flashVars.sound);

关于html - AS3 - 将变量数据从 HTML 页面传递到 flash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30812900/

相关文章:

actionscript-3 - flash as3 如何删除字节数组的一部分?

android-studio - "aapt tool failed", "values.xml:3: error: Found tag id where item is expected"

flash - AS3 数组向量

javascript - 从网页打开 finder/explorer 中的文件夹?

javascript - 在 Microsoft 平板电脑/触摸屏显示器上使用 mozilla firefox 禁用默认捏合缩放

html - 包含 SWF 的 DIV

html - CSS 将列表文本移动到另一侧

javascript - 如何使用 ChartJS 在水平条形图上绘制垂直线?

apache-flex - 0.9 版本的任何 Red5 工作示例项目

flash - Actionscript TCP 套接字无法为某些人发送消息