/* Friday 04/04/08 Example - followup to related raceEm.txt example that is achieved without using the Array() variable approach and without being able to use for loops (for loops are NOT just for breakfast!) */ race_btn.addEventListener(MouseEvent.CLICK, startRace); var r:Array = new Array(); r[0] = r1; r[1] = r2; // Array example makes code r[2] = r3; // shorter. Imagine if there were r[3] = r4; // 8 or 12 or 16 racing rectangles! var tmr:Timer = new Timer(100); tmr.addEventListener("timer", race); function startRace(evt:MouseEvent) { tmr.start(); } function race(evt:Event) { for (var i:int = 0; i < 4; i++) { r[i].x += Math.random() * 21; } for (i = 0; i < 4; i++) { if (r[i].x > finish.x) { tmr.stop(); // determine the winner NOT DONE } // Need to report who won for close races. } }