In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

クロージャを使ってaddEventListenerしたイベントをremoveEventListenerする。

http://level0.kayac.com/2009/09/event_closure.php
* 
* arguments.calleeについては下記のドキュメントをご覧ください。
* http://help.adobe.com/ja_JP/AS3LCR/Flash_10.0/arguments.html
Get Adobe Flash player
by otoyasumi 28 Sep 2009
/**
 * Copyright otoyasumi ( http://wonderfl.net/user/otoyasumi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/p8cP
 */

/**
 * http://level0.kayac.com/2009/09/event_closure.php
 * 
 * arguments.calleeについては下記のドキュメントをご覧ください。
 * http://help.adobe.com/ja_JP/AS3LCR/Flash_10.0/arguments.html
 */
package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;

	public class Test extends Sprite {
		private var TEST_STRING:String = "    ______\n   /  \    /\\n /  し (>)  (<)\\n | ∪    (__人__)  J | ________\n \  u   `⌒´   / | |          |\n ノ           \ | |          |\n\n      ____\n   /  \    ─\   チラッ\n /  し (>)  (●)\\n | ∪    (__人__)  J | ________\n \  u   `⌒´   / | |          |\n ノ           \ | |          |\n\n      ____\n   /::::::─三三─\\n /:::::::: ( ○)三(○)\\n |::::::::::::::::::::(__人__)::::  | ________\n  \:::::::::   |r┬-|  / | |          |\n ノ::::::::::::  `ー'´   \ | |          | \n\n      ____\n    /      \\n   /  ─    ─\\n /    (●)  (●) \\n |       (__人__)    |\n /     ∩ノ ⊃  /\n (  \ / _ノ |  |\n .\ “  /__|  |\n   \ /___ /      removeEventListener()されたお";
		
		public function Test() {
			var t:TextField = new TextField();
			
			t.width = 400;
			t.height = 600;
			addChild(t);
			
			var count:int = 0;
			var max_count:int = TEST_STRING.length;
			
			stage.addEventListener(Event.ENTER_FRAME, function():void {
				t.appendText( TEST_STRING.charAt(count) );
				count++;
				if (count >= max_count) {
					stage.removeEventListener(Event.ENTER_FRAME, arguments.callee);
				}
			});
		}
		
		
		
	}
}