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

クロージャってこういうこと? 「;」忘れの恐怖

Get Adobe Flash player
by coppieee 02 Dec 2009
    Embed
/**
 * Copyright coppieee ( http://wonderfl.net/user/coppieee )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/MgUP
 */

// forked from paq's forked from: クロージャってこういうこと?
// forked from paq's クロージャってこういうこと?
package {
	import com.bit101.components.PushButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	public class Main extends Sprite {
		public function Main() {
			createView();
			trace("onAnswerClick()で何が表示されるでしょうか?");
			trace("answerクリックで答え。");
		}
		private function onAnswerClick(e:MouseEvent):void {
			(function():Function { trace("A1"); return arguments.callee } )();
			(function():Function { trace("A2"); return arguments.callee } )()();
			
			trace("----");
			
			(function():Function { trace("B1"); return arguments.callee } )()
			(function():Function { trace("B2"); return arguments.callee } )()();
		}
		
		//ボタンとか生成
		private function createView():void {
			var b:PushButton = new PushButton(this);
			b.label = "answer";
			b.addEventListener(MouseEvent.CLICK, onAnswerClick);
			var t:TextField = new TextField();
			t.y = b.height;
			t.autoSize = TextFieldAutoSize.LEFT;
			addChild(t);
			trace = function(s:String):void { t.appendText(s + "\n"); };
		}
		private var trace:Function;
	}
}