示例代码:
用法1:
在下面的示例中,fscommand 动作设置 Flash Player,以便在释放按钮时,将 SWF 文件放大到整个显示器屏幕大小。
on (release) {
fscommand("fullscreen", true);
}
用法2:
下面的示例使用应用到 Flash 中按钮的 fscommand 动作打开 HTML 页中的 JavaScript 消息框。消息本身作为 fscommand 参数发送到 JavaScript。
必须将一个函数添加到包含 SWF 文件的 HTML 页。此函数 (myDocument_DoFSCommand) 位于 HTML 页中,等待 Flash 中的 fscommand 动作。当在 Flash 中触发 fscommand 后(例如,当用户按下按钮时),command 和 parameter 字符串被传递到 myDocument_DoFSCommand 函数。可以在 JavaScript 或 VBScript 代码中以任何需要的方式使用所传递的字符串。在此示例中,该函数包含一个条件 if 语句,该语句检查命令字符串是否为 "messagebox"。如果是,则
JavaScript 警告框(或“消息框”)打开并显示 parameters 字符串的内容。
function myDocument_DoFSCommand(command, args) {
if (command == "messagebox") {
alert(args);
}
}
在 Flash 文档中,将 fscommand 动作添加到按钮:
fscommand("messagebox", "This is a message box called from within Flash.")
也可以为 fscommand 动作和参数使用表达式,如下面的示例所示:
fscommand("messagebox", "Hello, " + name + ", welcome to our website!")
若要测试影片,请选择“文件”>“发布预览”>“HTML”。
注意:如果在 HTML“发布设置”中使用具有 FSCommand 模板的 Flash 发布 SWF 文件,则将自动插入 myDocument_DoFSCommand 函数。该 SWF 文件的 NAME 和 ID 属性将是文件名。