[AS3] argments.callee
argments#callee()
http://livedocs.adobe.com/flex/2_jp/langref/arguments.html#callee()
現在実行中の関数への参照を取得できるってことは
再帰的に行う処理で自分自身を呼び出さないやりかたも考えられますです
package {
import flash.display.Sprite;
public class ArgumentsExample extends Sprite {
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);
}
}
}
無名関数とかで参照が取れない場合とかもこんなんできるます
var i:int = 0;
addEventListener(Event.ENTER_FRAME, function(e:Event):void{
trace("hogehoge"+String(i++));
if(i > 100) {
removeEventListener(Event.ENTER_FRAME, arguments.callee);
}
}
素晴らしい