home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 150 / MOBICLIC150.ISO / pc / DATA / HOTE / launcher_as3 / launcher.swf / scripts / com / milanpresse / launcher / CapsuleAlgo.as next >
Text File  |  2012-12-18  |  12KB  |  352 lines

  1. package com.milanpresse.launcher
  2. {
  3.    import com.milanpresse.engine.Engine;
  4.    import com.milanpresse.engine.config.Config;
  5.    import com.milanpresse.engine.config.HostConfig;
  6.    import com.milanpresse.engine.medias.MediaSwf;
  7.    import com.milanpresse.engine.typeargument.ModuleCallerParameter;
  8.    import com.milanpresse.tools.GlobalesFunctions;
  9.    import com.milanpresse.tools.Stats;
  10.    import flash.display.DisplayObject;
  11.    import flash.display.Loader;
  12.    import flash.display.Sprite;
  13.    import flash.events.Event;
  14.    import flash.events.KeyboardEvent;
  15.    import flash.media.SoundTransform;
  16.    
  17.    public class CapsuleAlgo
  18.    {
  19.        
  20.       
  21.       private var _loader:Loader;
  22.       
  23.       private var _localConnection:HoteAS2LocalConnection;
  24.       
  25.       private var _module = null;
  26.       
  27.       private var _engine:Engine = null;
  28.       
  29.       private var _load_anim:MediaSwf = null;
  30.       
  31.       private var _menu:Menu;
  32.       
  33.       private var _activeModule:Module;
  34.       
  35.       private var _nextModule:Module;
  36.       
  37.       public var hostConfig:HostConfig;
  38.       
  39.       private var _hostAS2:HoteAS2;
  40.       
  41.       public var config:Config;
  42.       
  43.       public var launchFirstModule:Boolean = true;
  44.       
  45.       private var _stats:Stats;
  46.       
  47.       public var mask:Sprite;
  48.       
  49.       private var _isPadStarted:Boolean = false;
  50.       
  51.       private var _tempModuleObject:Object;
  52.       
  53.       private var _moduleCallerParameters:ModuleCallerParameter;
  54.       
  55.       public function CapsuleAlgo(param1:*)
  56.       {
  57.          this._tempModuleObject = {};
  58.          super();
  59.          this._module = param1;
  60.          this._engine = this._module.engine as Engine;
  61.          this.config = this._engine.config;
  62.          this.config.subtitlesBloc.visible = false;
  63.          this.getConfig();
  64.       }
  65.       
  66.       private function getConfig() : void
  67.       {
  68.          this.hostConfig = this._engine.host.hostConfig;
  69.          this._module.changeModule = this.changeModule;
  70.          this._module.hostConfig = this.hostConfig;
  71.          this.start();
  72.       }
  73.       
  74.       public function start(param1:* = null) : void
  75.       {
  76.          var p:* = param1;
  77.          this._engine.fullscreen = this.hostConfig.fullscreen;
  78.          (this._module as DisplayObject).stage.quality = this.hostConfig.quality;
  79.          (this._module as DisplayObject).stage.addEventListener(KeyboardEvent.KEY_DOWN,this.statsKeyDownHandler);
  80.          var _loc4_:int = 0;
  81.          var _loc5_:* = ┬º┬ºcheckfilter(this._engine.config.XmlConfig.Module.Config.Param);
  82.          var _loc3_:* = new XMLList("");
  83.          ┬º┬ºpush(┬º┬ºfindproperty(uint));
  84.          this._engine.config.XmlConfig.Module.Config.Param.(@nom == "numMag");
  85.          ┬º┬ºpop().projetNum = this._engine.config.uint(_loc3_[0].@valeur);
  86.          this.createLayers();
  87.          this.showAnim();
  88.          this.loadMenu();
  89.       }
  90.       
  91.       private function statsKeyDownHandler(param1:KeyboardEvent) : void
  92.       {
  93.          if(param1.ctrlKey && param1.altKey)
  94.          {
  95.             this._stats = new Stats();
  96.             this._engine.config.ROOT_APP.addChild(this._stats);
  97.          }
  98.       }
  99.       
  100.       public function maskShow() : void
  101.       {
  102.          (this.config.scene as Sprite).mask = this.mask;
  103.          this.config.ROOT_APP.addChild(this.mask);
  104.          if(this._menu != null)
  105.          {
  106.             this._menu.maskHide();
  107.          }
  108.       }
  109.       
  110.       public function maskHide() : void
  111.       {
  112.          (this.config.scene as Sprite).mask = null;
  113.          if(this.mask.parent != null)
  114.          {
  115.             this.config.ROOT_APP.removeChild(this.mask);
  116.          }
  117.          if(this._menu != null)
  118.          {
  119.             this._menu.maskShow();
  120.          }
  121.       }
  122.       
  123.       public function createLayers() : void
  124.       {
  125.          this.config.layers["activeAS2Module"] = this.config.scene.addChildAt(new Sprite(),this.config.scene.getChildIndex(this.config.layers["menu"]));
  126.          this.config.layers["activeModule"] = this.config.scene.addChildAt(new Sprite(),this.config.scene.getChildIndex(this.config.layers["menu"]));
  127.          this.config.layers["activeAS2Module"].visible = false;
  128.          this.mask = GlobalesFunctions.createRectangle({
  129.             "w":800,
  130.             "h":600
  131.          });
  132.          this.maskShow();
  133.       }
  134.       
  135.       public function showAnim() : void
  136.       {
  137.          this._load_anim = this._engine.getMedia({"id":"LOAD_ANIM"}) as MediaSwf;
  138.          this.config.layers["load_anim"].addChild(this._load_anim.swf);
  139.          this._load_anim.swf.mouseEnabled = false;
  140.          this._load_anim.swf.mouseChildren = false;
  141.          this._load_anim.swf.enabled = false;
  142.          this._load_anim.swf.visible = true;
  143.          this._load_anim.swf.soundTransform = new SoundTransform(1);
  144.          this._load_anim.swfContent.gotoAndPlay(1);
  145.       }
  146.       
  147.       public function loadMenu() : void
  148.       {
  149.          this._menu = new Menu(this._engine.getMedia({"id":"PAD"}) as MediaSwf,this,this.menuIsStarted);
  150.       }
  151.       
  152.       public function menuIsStarted() : void
  153.       {
  154.          this._menu.visible = false;
  155.          this._menu.addToParent(this.config.layers["menu"]);
  156.          this.hostAS2Load();
  157.       }
  158.       
  159.       public function hostAS2Load() : void
  160.       {
  161.          this._hostAS2 = new HoteAS2(this,this.hostIsInitialized);
  162.       }
  163.       
  164.       public function hostIsInitialized() : void
  165.       {
  166.          this._hostAS2.addToParent(this.config.layers["activeAS2Module"]);
  167.          if(this.config.context.urlParameters.ModuleId != undefined)
  168.          {
  169.             this.loadModule(new ModuleCallerParameter({"id":this.config.context.urlParameters.ModuleId}));
  170.          }
  171.          else
  172.          {
  173.             this.loadModule(new ModuleCallerParameter({"id":this.hostConfig.firstModuleToLaunch}));
  174.          }
  175.       }
  176.       
  177.       private function loadModule(param1:ModuleCallerParameter) : void
  178.       {
  179.          this._nextModule = new Module(param1,this,this._hostAS2);
  180.          this._nextModule.init(this.moduleIsInit);
  181.       }
  182.       
  183.       public function activeModuleDestroy() : void
  184.       {
  185.          if(this._activeModule != null)
  186.          {
  187.             this._activeModule.destroy();
  188.          }
  189.       }
  190.       
  191.       public function moduleAnimIsInit(param1:Object = null) : void
  192.       {
  193.       }
  194.       
  195.       public function moduleIsInit() : void
  196.       {
  197.          this._activeModule = this._nextModule;
  198.          this._menu.pad.refresh();
  199.          this._nextModule = null;
  200.          this.waitLoadAnimEnd();
  201.       }
  202.       
  203.       public function moduleAnimShow() : void
  204.       {
  205.          this._load_anim.swf.visible = true;
  206.          this._load_anim.swf.soundTransform = new SoundTransform(1);
  207.          this._load_anim.swfContent.gotoAndStop(this._load_anim.swfContent.totalFrames);
  208.       }
  209.       
  210.       public function moduleAnimHide() : void
  211.       {
  212.          this._load_anim.swf.visible = false;
  213.          this._engine.destroyMedia(this._load_anim.id);
  214.          this._load_anim = null;
  215.       }
  216.       
  217.       public function waitLoadAnimEnd() : void
  218.       {
  219.          if(this._load_anim != null)
  220.          {
  221.             if(this._load_anim.timeline.currentFrame == this._load_anim.timeline.totalFrames)
  222.             {
  223.                this.moduleStart();
  224.             }
  225.             else
  226.             {
  227.                this._load_anim.timeline.addEventListener(Event.ENTER_FRAME,this.onEnterFrame);
  228.             }
  229.          }
  230.          else
  231.          {
  232.             this.moduleStart();
  233.          }
  234.       }
  235.       
  236.       private function onEnterFrame(param1:Event) : void
  237.       {
  238.          if(this._load_anim.timeline.currentFrame == this._load_anim.timeline.totalFrames)
  239.          {
  240.             this._load_anim.timeline.removeEventListener(Event.ENTER_FRAME,this.onEnterFrame);
  241.             this.moduleStart();
  242.          }
  243.       }
  244.       
  245.       public function moduleStart() : void
  246.       {
  247.          if(this._activeModule.asVersion == 3)
  248.          {
  249.             this.config.layers["activeAS2Module"].visible = false;
  250.             this.config.layers["activeModule"].addChild(this._activeModule.moduleMain);
  251.          }
  252.          else
  253.          {
  254.             this.config.layers["activeAS2Module"].visible = true;
  255.          }
  256.          this._activeModule.start(this.moduleIsStart);
  257.       }
  258.       
  259.       public function moduleIsStart() : void
  260.       {
  261.          (this._module as DisplayObject).stage.removeEventListener(KeyboardEvent.KEY_DOWN,this.statsKeyDownHandler);
  262.          var _loc1_:Boolean = true;
  263.          if(this._activeModule.mediaSwf.data.nodexml.hasOwnProperty("@padShow"))
  264.          {
  265.             _loc1_ = this._activeModule.mediaSwf.data.nodexml.@padShow.toString() == "true" ? true : false;
  266.          }
  267.          this._menu.visible = _loc1_;
  268.          if(this._load_anim != null)
  269.          {
  270.             this.moduleAnimHide();
  271.          }
  272.       }
  273.       
  274.       public function changeModule(param1:Object) : void
  275.       {
  276.          this._moduleCallerParameters = new ModuleCallerParameter(param1);
  277.          this._menu.pad.close();
  278.          this._menu.visible = false;
  279.          this.changeModuleAdaptParams();
  280.       }
  281.       
  282.       public function print(param1:Object) : void
  283.       {
  284.       }
  285.       
  286.       private function changeModuleAdaptParams() : void
  287.       {
  288.          this._activeModule.getConfig(this.getConfigReturn);
  289.       }
  290.       
  291.       private function getConfigReturn(param1:Object) : void
  292.       {
  293.          var _loc2_:String = null;
  294.          this._moduleCallerParameters.fromId = param1.id;
  295.          this._moduleCallerParameters.fromCodeRub = param1.rubriqueCode;
  296.          this._moduleCallerParameters.fromNumMod = param1.moduleNum;
  297.          if(this._moduleCallerParameters.id == null || this._moduleCallerParameters.id == "")
  298.          {
  299.             this._moduleCallerParameters.codeRub = this._moduleCallerParameters.codeRub == null || this._moduleCallerParameters.codeRub == "" ? this._moduleCallerParameters.fromCodeRub : this._moduleCallerParameters.codeRub;
  300.             _loc2_ = this._moduleCallerParameters.codeRub + this._engine.config.projetNumStr;
  301.             this._moduleCallerParameters.id = _loc2_ + "_" + GlobalesFunctions.gimme2digits(this._moduleCallerParameters.numMod);
  302.          }
  303.          this._moduleCallerParameters.type = "swf";
  304.          this.loadModule(this._moduleCallerParameters);
  305.       }
  306.       
  307.       public function destroy() : void
  308.       {
  309.       }
  310.       
  311.       public function get activeModule() : MediaSwf
  312.       {
  313.          return this._activeModule.mediaSwf;
  314.       }
  315.       
  316.       public function get engine() : Engine
  317.       {
  318.          return this._engine;
  319.       }
  320.       
  321.       public function get musicOn() : Boolean
  322.       {
  323.          return this.config.musicOn;
  324.       }
  325.       
  326.       public function set musicOn(param1:Boolean) : void
  327.       {
  328.          if(this.config.musicOn == param1)
  329.          {
  330.             return;
  331.          }
  332.          this.config.musicOn = param1;
  333.          this._activeModule.musicOn = param1;
  334.       }
  335.       
  336.       public function get subtitlesOn() : Boolean
  337.       {
  338.          return this.config.subtitlesOn;
  339.       }
  340.       
  341.       public function set subtitlesOn(param1:Boolean) : void
  342.       {
  343.          if(this.config.subtitlesOn == param1)
  344.          {
  345.             return;
  346.          }
  347.          this.config.subtitlesOn = param1;
  348.          this._activeModule.subtitlesOn = param1;
  349.       }
  350.    }
  351. }
  352.