Forked from: 9re's Scope of the Function diff:14 forked from: Scope of the Function 9re forked:1favorite:0lines:40license : MIT License modified : 2009-06-30 14:34:20 Embed Tweet // forked from 9re's Scope of the Function package { import flash.events.MouseEvent; import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFormat; public class TestEvaluation extends Sprite { /* This code is a bad code for the purpose, but is a good example for learning scope of the functions compare to the original version: http://wonderfl.net/code/21e27da431c30d9908d605f3759bb2856d808125 */ public function TestEvaluation () { var sp:Sprite; var tf:TextField; for (var i:int = 0; i < 10; ++i) { sp = new Sprite(); sp.graphics.beginFill(0, 0.7); sp.graphics.drawRect(0, 5, 40, 30); sp.x = stage.stageWidth / 2 - 20; sp.y = 32 + 40 * i; tf = new TextField(); tf.defaultTextFormat = new TextFormat("_sans", 30, 0xffffff, true); tf.width = 40; tf.height = 36; tf.x = 2; tf.selectable = false; tf.mouseEnabled = false; sp.addChild(tf); sp.buttonMode = true; sp.tabEnabled = false; // save tf and i to the local variables of the closure //************************************************ sp.addEventListener(MouseEvent.MOUSE_OVER, (function ($tf:TextField, $i:int):Function { return function (e:MouseEvent):void { $tf.text = $i.toString(); } })(tf, i)); sp.addEventListener(MouseEvent.MOUSE_OUT, (function ($tf:TextField, $i:int):Function { return function (e:MouseEvent):void { $tf.text = ""; } })(tf, i)); //************************************************ addChild(sp); } } } } Code Fullscreen Preview Fullscreen tabEnabled mouseEnabled MouseEvent.MOUSE_OUT MouseEvent.MOUSE_OVER buttonMode MouseEvent addEventListener toString height width text TextFormat addChild Sprite int sort new page view favorite forked pv0 forked from: forked from: Scop.. Perplex forked:0 favorite:0lines:40 (diff:1)