asfunction 协议

asfunction:function:Function, parameter:String

用于 HTML 文本字段中 URL 的特殊协议,该协议允许 HREF 链接调用 ActionScript 函数。在 HTML 文本字段中,可以使用 HTML A 标签创建链接。A 标签的 HREF 属性包含使用 HTTP、HTTPS 或 FTP 等标准协议的 URL。asfunction 协议是特定于 Flash 的一个附加协议,它可使链接调用 ActionScript 函数。

可用性:ActionScript 1.0、Flash Player 5

参数

function:String ― 函数的标识符。

parameter:String ― 一个字符串,传递给在 function 参数中命名的函数。

示例

在下面的示例中,定义了 playMP3() 函数。创建并设置了 TextField 对象 list_txt,因此可以呈现 HTML 文本。文本 Track 1 和 Track 2 是文本字段中的链接。当用户单击任一链接并播放作为 asfunction 调用的参数传递的 MP3 时,会调用 playMP3() 函数。

var myMP3:Sound = new Sound();
function playMP3(mp3:String) {
 myMP3.loadSound(mp3, true);
 myMP3.onLoad = function(success) {
 if (!success) {
 // code to handle errors here
 }
 };
}
this.createTextField("list_txt", this.getNextHighestDepth(), 0, 0, 200, 100);
list_txt.autoSize = true;
list_txt.html = true;
list_txt.multiline = true;
list_txt.htmlText = "<a href=\"asfunction:playMP3, track1.mp3\">Track 1</a><br>";
list_txt.htmlText += "<a href=\"asfunction:playMP3, track2.mp3\">Track 2</a><br>";

当单击某链接时,该 MP3 声音文件会流入 Flash Player。

请参阅

htmlText(TextField.htmlText 属性)