首页 > flash&flex > as3移除匿名监听函数

as3移除匿名监听函数

2009年3月16日 admin 发表评论 阅读评论

有时候写代码的时候图方便,比如在监听句柄中使用添加监听时的参数,在监听中直接用匿名函数,可以使用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: 68% [?]

分类: flash&flex 标签: , ,
  1. 2009年6月15日14:46 | #1

    The article is ver good. Write please more

  2. 2009年11月18日22:55 | #2

    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

  1. 本文目前尚无任何 trackbacks 和 pingbacks.