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

forked from: forked from: flash on 2012-1-6

Get Adobe Flash player
by programmeraxel 06 Jan 2012
    Embed
/**
 * Copyright programmeraxel ( http://wonderfl.net/user/programmeraxel )
 * GNU General Public License, v3 ( http://www.gnu.org/licenses/quick-guide-gplv3.html )
 * Downloaded from: http://wonderfl.net/c/aUZv
 */

// forked from YellowAfterlife's forked from: flash on 2012-1-6
// forked from programmeraxel's flash on 2012-1-6
package  
{
    import flash.display.*;
    import flash.events.*;
    import com.demonsters.debugger.MonsterDebugger;
    import flash.events.Event;
    import flash.events.TimerEvent;
    import flash.utils.Timer;
    import flash.text.TextField;
    import flash.text.TextFormat;
    public class MonsterConnector extends Sprite {
        // constructor:
        public function MonsterConnector():void {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        // init:
        private function init(e:Event = null):void {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            // adventure begins:
            _sleep();
            _trace2();
            trace2("Initialization done.");
            // add event listeners:
            root.addEventListener("allComplete", allCompleteHandler);
            stage.addEventListener(MouseEvent.CLICK, onMouseClick);
            stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
        }
        // Startup event:
        private var loader:LoaderInfo;
        public var game:Object;
        private function allCompleteHandler(e:Event):void {
            trace2("Startup starts...");
            try {
                var loader:LoaderInfo = LoaderInfo(e.target);
                var ev:MouseEvent = new MouseEvent(MouseEvent.CLICK, true, false, 0, 0);
                if (loader.content.root.stage == null) return;
                trace2("Startup starts...");
                MonsterDebugger.initialize(loader.content.root);
                MonsterDebugger.trace(this, loader.loaderURL);
                MonsterDebugger.trace(this, 'test');
                stage.quality = StageQuality.LOW;
                trace2("Startup works.");
                traceChildren(stage);
                //trace2('yelow');
                //var test:test_prot = new test_prot();
                //sleep(10000, function():void {
               //     game.message_btn.dispatchEvent(ev);
               // } );
            } catch (e:Error) {
                trace2("Error in startup: " + e + "\r" + e.getStackTrace());
            }
       }
 
 
        public function onMouseClick(e:MouseEvent):void {
            trace2("Click target: " + e.target);
        }
        public function onKeyDown(e:KeyboardEvent):void {
            if (e.keyCode == 192) { // [`~] key
                trace2c();
            }
        }
        //{ Sleep
        public var sleepTimer:Timer;
        public var sleepFunc:Function;
        public function sleepComplete(e:Event):void {
            sleepTimer.reset();
            sleepFunc();
        }
        public function sleep(time:uint, func:Function):void {
            sleepTimer.delay = time;
            sleepFunc = func;
            sleepTimer.reset();
            sleepTimer.start();
        }
        public function _sleep():void {
            sleepTimer = new Timer(0, 0);
            sleepTimer.addEventListener(TimerEvent.TIMER, sleepComplete);
        }
 
        //}
        //{ Trace2
        public var output:TextField;
        public function trace2(...data):void {
            var t:String = '\r';
            var l:int = data.length;
            for (var i:int = 0; i < l; i++) t += data[i] + ' ';
            output.appendText(t);
            MonsterDebugger.trace(this, t);
            addChild(output);
        }
        public function trace2c():void {
            output.text = '';
        }
        public function _trace2():void {
            output = new TextField();
            output.autoSize = "left";
            output.x = 10;
            output.y = 10;
            output.defaultTextFormat = new TextFormat("Courier New", 12, 0xFF0000);
            output.text = "Tracelog:";
            addChild(output);
        }
        
        public function traceChildren(what:DisplayObjectContainer, c:int = 0):void {
    var j:int, child:DisplayObject, out:String;
    for (var i:int = 0, l:int = what.numChildren; i < l; i++) {
        child = what.getChildAt(i);
        // add 'tabs' before text:
        for (j = 0, out = ''; j < c; j++) out += '. ';
        // add component's toString():
        out += child.toString();
        // display output:
        trace2(out);
        // if child is container too, trace its children:
        if (child is DisplayObjectContainer) {
            traceChildren(child as DisplayObjectContainer, c + 1);
        }
    }
}
        //}        
    }
}