数人对asfunction都比较陌生,但实际上它在Flash5就已经出现了。
asfunction是什么东东呢?它是一个专用于Flash的HTML附加协议,用来在Flash的HTML文本字段中调用actionscript函数。说来太抽象,看下面的例子:
在舞台上放5个动态文本,实例名分别为dt1~dt5。属性面板中选中下面的项:
再放一个MC,实例名为ball。
然后就是在第1帧中加AS:
var v = 20;
function goDir(dir) {
switch (dir) {
case "left" :
ball.onEnterFrame = function() {
this._x -= v;
if (this._x<0) {
this._x = Stage.width;
}
};
break;
case "right" :
ball.onEnterFrame = function() {
this._x += v;
if (this._x>Stage.width) {
this._x = 0;
}
};
break;
case "up" :
ball.onEnterFrame = function() {
this._y -= v;
if (this._y<0) {
this._y = Stage.height;
}
};
break;
case "down" :
ball.onEnterFrame = function() {
this._y += v;
if (this._y>Stage.height) {
this._y = 0;
}
};
break;
case "stop" :
delete ball.onEnterFrame;
break;
}
}
dt1.htmlText = "<a href=''asfunction:goDir,up''>Up</a>";
dt2.htmlText = "<a href=''asfunction:goDir,down''>Down</a>";
dt3.htmlText = "<a href=''asfunction:goDir,left''>Left</a>";
dt4.htmlText = "<a href=''asfunction:goDir,right''>Right</a>";
dt5.htmlText = "<a href=''asfunction:goDir,stop''>Stop</a>";
源文件下载: function goDir(dir) {
switch (dir) {
case "left" :
ball.onEnterFrame = function() {
this._x -= v;
if (this._x<0) {
this._x = Stage.width;
}
};
break;
case "right" :
ball.onEnterFrame = function() {
this._x += v;
if (this._x>Stage.width) {
this._x = 0;
}
};
break;
case "up" :
ball.onEnterFrame = function() {
this._y -= v;
if (this._y<0) {
this._y = Stage.height;
}
};
break;
case "down" :
ball.onEnterFrame = function() {
this._y += v;
if (this._y>Stage.height) {
this._y = 0;
}
};
break;
case "stop" :
delete ball.onEnterFrame;
break;
}
}
dt1.htmlText = "<a href=''asfunction:goDir,up''>Up</a>";
dt2.htmlText = "<a href=''asfunction:goDir,down''>Down</a>";
dt3.htmlText = "<a href=''asfunction:goDir,left''>Left</a>";
dt4.htmlText = "<a href=''asfunction:goDir,right''>Right</a>";
dt5.htmlText = "<a href=''asfunction:goDir,stop''>Stop</a>";
点击浏览该文件
点击浏览该文件
