// Decompiled by AS3 Sorcerer 6.78
// www.buraks.com/as3sorcerer

//GameLoader

package 
{
    import flash.display.Sprite;
    import flash.display.Loader;
    import flash.text.TextField;
    import projects.tanks.clients.tankslauncershared.dishonestprogressbar.DishonestProgressBar;
    import projects.tanks.clients.fp10.TanksLauncher.background.Background;
    import flash.events.Event;
    import flash.system.ApplicationDomain;
    import flash.desktop.NativeApplication;
    import flash.events.KeyboardEvent;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.display.StageQuality;
    import flash.system.LoaderContext;
    import flash.net.URLVariables;
    import flash.net.URLRequest;
    import flash.net.URLLoader;
    import flash.net.URLLoaderDataFormat;
    import flash.utils.ByteArray;
    import flash.display.LoaderInfo;
    import flash.display.NativeWindowInitOptions;
    import flash.display.NativeWindow;
    import projects.tanks.clients.fp10.TanksLauncher.SmartErrorHandler;
    import flash.display.StageDisplayState;
    import flash.ui.Keyboard;

    public class GameLoader extends Sprite 
    {

        private static var GAME_URL:String = "http://93.78.105.80:8080/resource/";
        private static const ENTRANCE_MODEL_OBJECT_LOADED_EVENT:String = "EntranceModel.objectLoaded";

        private var loader:Loader;
        private var locale:String;
        public var log:TextField;
        private var fullScreen:Boolean;
        private var _dishonestProgressBar:DishonestProgressBar;
        private var _background:Background;

        public function GameLoader()
        {
            addEventListener(Event.ADDED_TO_STAGE, this.init);
        }

        public static function findClass(param1:String):Class
        {
            return (Class(ApplicationDomain.currentDomain.getDefinition(param1)));
        }


        private function init(e:Event=null):void
        {
            trace("AIR SDK Version: ", NativeApplication.nativeApplication.runtimeVersion);
            removeEventListener(Event.ADDED_TO_STAGE, this.init);
            this.configureStage();
            this.createBackground();
            stage.addEventListener(KeyboardEvent.KEY_DOWN, this.onKey);
            this.createDishonestProgressBar();
            try
            {
                this.loadLibrary();
            }
            catch(e:Error)
            {
                this.handleLoadingError(e.getStackTrace(), "0");
            };
        }

        private function configureStage():void
        {
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.quality = StageQuality.LOW;
            stage.stageFocusRect = false;
            mouseEnabled = false;
            tabEnabled = false;
            stage.addEventListener(ENTRANCE_MODEL_OBJECT_LOADED_EVENT, this.onEntranceModelObjectLoaded);
        }

        private function createBackground():void
        {
            this._background = new Background();
            stage.addChild(this._background);
        }

        private function createDishonestProgressBar():void
        {
            this._dishonestProgressBar = new DishonestProgressBar("RU", this.progressBarFinished);
            stage.addChild(this._dishonestProgressBar);
            this._dishonestProgressBar.start();
        }

        private function progressBarFinished():void
        {
            this.removeFromStageBackground();
            this.removeFromStageDishonestProgressBar();
        }

        private function removeFromStageBackground():void
        {
            if (stage.contains(this._background))
            {
                stage.removeChild(this._background);
            };
        }

        private function removeFromStageDishonestProgressBar():void
        {
            if (stage.contains(this._dishonestProgressBar))
            {
                stage.removeChild(this._dishonestProgressBar);
            };
        }

        private function onEntranceModelObjectLoaded(event:Event):void
        {
            trace("entrance model obj loaded");
            stage.removeEventListener(ENTRANCE_MODEL_OBJECT_LOADED_EVENT, this.onEntranceModelObjectLoaded);
            this.removeFromStageBackground();
            this._dishonestProgressBar.forciblyFinish();
        }

        private function loadLibrary():void
        {
            var context:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
            var flashvars:URLVariables = new URLVariables();
            flashvars["locale"] = "ru";
            flashvars["rnd"] = Math.random();
            var urlReq:URLRequest = new URLRequest("battles.swf");
            var urlLoader:URLLoader = new URLLoader();
            urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
            urlLoader.addEventListener(Event.COMPLETE, this.byteArrayLoadComplete);
            urlLoader.load(urlReq);
        }

        private function byteArrayLoadComplete(event:Event):void
        {
            var bytes:ByteArray = (URLLoader(event.target).data as ByteArray);
            this.loader = new Loader();
            var loaderContext:LoaderContext = new LoaderContext(false, new ApplicationDomain(ApplicationDomain.currentDomain));
            var loaderInfo:LoaderInfo = this.loader.contentLoaderInfo;
            loaderInfo.addEventListener(Event.COMPLETE, this.onComplete, false, 0, true);
            loaderContext.allowCodeImport = true;
            this.loader.loadBytes(bytes, loaderContext);
            this.progressBarFinished();
            var _loc2_:NativeWindowInitOptions = new NativeWindowInitOptions();
            _loc2_.renderMode = "direct";
            _loc2_.maximizable = true;
            window = new NativeWindow(_loc2_);
            window.minSize = new Point(0x0400, 0x0300);
            window.maxSize = new Point(4095, 2880);
            window.stage.stageWidth = 0x0400;
            window.stage.stageHeight = 0x0300;
        }

        public function logEvent(entry:String):void
        {
            this.log.appendText((entry + "\n"));
            trace(entry);
        }

        private function onComplete(e:Event):void
        {
            this.loader.removeEventListener(Event.COMPLETE, this.onComplete);
            var mainClass:Class = Class(this.loader.contentLoaderInfo.applicationDomain.getDefinition("Game"));
            var obj:* = new (mainClass)();
            obj.SUPER(stage);
            addChild(obj);
        }

        private function handleLoadingError(errorMessage:String, errorCode:String):void
        {
            var seh:SmartErrorHandler = new SmartErrorHandler(errorMessage, errorCode);
            stage.addChild(seh);
            seh.handleLoadingError();
        }

        private function onKey(e:KeyboardEvent):void
        {
            switch (e.keyCode)
            {
                case Keyboard.F11:
                default:
                    this.fullScreen = (!(this.fullScreen));
                    if (this.fullScreen)
                    {
                        stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
                        return;
                    };
                    stage.displayState = StageDisplayState.NORMAL;
                    return;
            };
        }


    }
}//package 

window жалуется как исправить ?