as3移除匿名监听函数
有时候写代码的时候图方便,比如在监听句柄中使用添加监听时的参数,在监听中直接用匿名函数,可以使用arguments.callee获得该匿名监听函数的引用,来移除,举个简单的例子
m_someBtn.addEventListener(MouseEvent.CLICK,function(e:MouseEvent):void{
(e.target).removeEventListener(MouseEvent.CLICK,arguments.callee);
…
})
arguments.callee 是as2时代就有的东西了,可以方便的引用当前执行的函数,引个例子吧
private var count:int = 1;
public function ArgumentsExample() {
firstFunction(true);
}
public function firstFunction(callSecond:Boolean) {
trace(count + “: firstFunction”);
if(callSecond) {
secondFunction(arguments.callee);
}
else {
trace(”CALLS STOPPED”);
}
}
public function secondFunction(caller:Function) {
trace(count + “: secondFunction\n”);
count++;
caller(false);
}
Popularity: 93% [?]
The article is ver good. Write please more
it seems that i’d better enforce api studing for mention above as to caller as white as an absolutely blanky fucky sheet to me…… hope you write more, i am after,gaga