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

Event Sort

Get Adobe Flash player
by bkzen 20 May 2011

    Talk

    makc3d at 12 Sep 2012 16:38
    месье знает толк в извращениях

    Tags

    Embed
/**
 * Copyright bkzen ( http://wonderfl.net/user/bkzen )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/3hvo
 */

// forked from saharan's Sleep sort
package {
    import flash.events.*;
    import flash.utils.*;
    import flash.text.TextField;
    import flash.display.Sprite;
    public class EventSort extends Sprite {
        private var _trace:TextField;
        public function EventSort() {
            initialize();
        }
        
        private function initialize():void {
            _trace = new TextField();
            _trace.wordWrap = true;
            _trace.width = 465;
            _trace.height = 465;
            addChild(_trace);
            var numbers:Array = [];
            var i:int;
            for (i = 0; i < 200; i++) {
                numbers[i] = i;
                var flip:int = Math.random() * i;
                var temp:uint = numbers[i];
                numbers[i] = numbers[flip];
                numbers[flip] = temp;
            }
            sort(numbers);
        }

        private function sort(numbers:Array):void {
            for (var i:int = 0; i < numbers.length; i++) {
                var number:uint = numbers[i] as uint;
                addEventListener("sort", getHandler(number), false, -number);
            }
            dispatchEvent(new Event("sort"));
        }
        
        private function getHandler(number: uint): Function
        {
            return function(e: Event): void
            {
                _trace.appendText(number + " ");
            }
        }
    }
}