home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 150 / MOBICLIC150.ISO / pc / DATA / HOTE / launcher_as3 / launcher.swf / scripts / com / milanpresse / launcher / Module.as < prev    next >
Text File  |  2012-12-18  |  12KB  |  371 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.errors.GameEngineError;
  6.    import com.milanpresse.engine.medias.Media;
  7.    import com.milanpresse.engine.medias.MediaSwf;
  8.    import com.milanpresse.engine.typeargument.ModuleCallerParameter;
  9.    import com.milanpresse.tools.GlobalesFunctions;
  10.    import flash.display.DisplayObject;
  11.    import flash.display.Loader;
  12.    import flash.display.MovieClip;
  13.    import flash.events.Event;
  14.    
  15.    public class Module
  16.    {
  17.        
  18.       
  19.       protected var _mediaSwf:MediaSwf = null;
  20.       
  21.       protected var _initParams:ModuleCallerParameter;
  22.       
  23.       protected var _moduleMain;
  24.       
  25.       private var _loader:Loader;
  26.       
  27.       private var _callback:Function = null;
  28.       
  29.       private var _callback_getConfig:Function = null;
  30.       
  31.       private var _callback_start:Function = null;
  32.       
  33.       private var _callback_moduleAnimIsInit:Function = null;
  34.       
  35.       private var _moduleController:CapsuleAlgo;
  36.       
  37.       private var _engine:Engine;
  38.       
  39.       private var _hostAS2:HoteAS2;
  40.       
  41.       private var _config:Config = null;
  42.       
  43.       private var _loadAnim:MediaSwf;
  44.       
  45.       private var _loadBar:MediaSwf;
  46.       
  47.       public function Module(param1:ModuleCallerParameter, param2:CapsuleAlgo, param3:HoteAS2)
  48.       {
  49.          super();
  50.          this._initParams = param1;
  51.          this._moduleController = param2;
  52.          this._hostAS2 = param3;
  53.          this._mediaSwf = this._moduleController.engine.getMedia({"id":this._initParams.id}) as MediaSwf;
  54.          if(this._mediaSwf == null)
  55.          {
  56.             throw new GameEngineError("Could not find info of module " + this._initParams.id + ". Check the ressource info is available in xml of the project.");
  57.          }
  58.          this._moduleMain = this._mediaSwf.swf;
  59.       }
  60.       
  61.       public function get moduleMain() : DisplayObject
  62.       {
  63.          return this._moduleMain;
  64.       }
  65.       
  66.       public function get id() : String
  67.       {
  68.          return this._mediaSwf.id;
  69.       }
  70.       
  71.       public function get asVersion() : Number
  72.       {
  73.          return this._mediaSwf.asVersion;
  74.       }
  75.       
  76.       public function get mediaSwf() : MediaSwf
  77.       {
  78.          return this._mediaSwf;
  79.       }
  80.       
  81.       public function init(param1:Function) : void
  82.       {
  83.          var changeModuleAS2Params:Object = null;
  84.          var prop:String = null;
  85.          var callback:Function = param1;
  86.          this._callback = callback;
  87.          if(this._mediaSwf.data.nodexml.hasOwnProperty("@fps"))
  88.          {
  89.             this._moduleController.engine.setFrameRate(Number(this._mediaSwf.data.nodexml.@fps));
  90.          }
  91.          else
  92.          {
  93.             this._moduleController.engine.setFrameRate(12);
  94.          }
  95.          if(this.asVersion == 3)
  96.          {
  97.             this._moduleController.maskShow();
  98.             this.animLoad();
  99.          }
  100.          else
  101.          {
  102.             this._moduleController.maskHide();
  103.             this._mediaSwf.swf = new MovieClip();
  104.             this._config = new Config();
  105.             this._config.moduleName = this.id;
  106.             this._config.projetNumStr = this.id.substr(3,6);
  107.             this._config.rubriqueCode = this.id.substr(0,3);
  108.             this._mediaSwf.swf.sleep = function():void
  109.             {
  110.                _hostAS2.sleepModule();
  111.             };
  112.             this._mediaSwf.swf.wake = function():void
  113.             {
  114.                _hostAS2.wakeModule();
  115.             };
  116.             this._mediaSwf.swf.config = this._config;
  117.             this._moduleController.launchFirstModule = false;
  118.             this._moduleController.config.layers["activeAS2Module"].visible = true;
  119.             changeModuleAS2Params = {};
  120.             for(prop in this._initParams.CallerParameters)
  121.             {
  122.                changeModuleAS2Params[prop] = this._initParams.CallerParameters[prop];
  123.             }
  124.             changeModuleAS2Params.id = this._initParams.id;
  125.             this._hostAS2.loadModule(changeModuleAS2Params,this.moduleAS2Loaded);
  126.             this._moduleController.activeModuleDestroy();
  127.          }
  128.       }
  129.       
  130.       private function animLoad() : void
  131.       {
  132.          var _loc1_:* = null;
  133.          var _loc2_:String = null;
  134.          if(this._moduleController.launchFirstModule)
  135.          {
  136.             this._moduleController.launchFirstModule = false;
  137.             this.animLoaded1();
  138.          }
  139.          else
  140.          {
  141.             if(this._mediaSwf.data.nodexml.hasOwnProperty("@loadAnim"))
  142.             {
  143.                _loc2_ = this._mediaSwf.data.nodexml.@loadAnim.toString();
  144.                if(_loc2_ == "MODULE")
  145.                {
  146.                   _loc1_ = GlobalesFunctions.getDirectoryPathOfFile(this._mediaSwf.path) + "/C_" + this.id + "/C_" + this.id + ".swf";
  147.                }
  148.                else if(_loc2_ == "RUBRIQUE")
  149.                {
  150.                   _loc1_ = GlobalesFunctions.getDirectoryPathOfFile(GlobalesFunctions.getDirectoryPathOfFile(this._mediaSwf.path)) + "/_COMMUN/load_anim/C_" + this.id.substr(0,6) + ".swf";
  151.                }
  152.                else
  153.                {
  154.                   _loc1_ = this._moduleController.engine.config.modulePath + "/DATA/_COMMUN/load_anim_modules/" + this._mediaSwf.data.nodexml.@loadAnim.toString() + ".swf";
  155.                }
  156.             }
  157.             else
  158.             {
  159.                _loc1_ = this._moduleController.engine.config.modulePath + "/DATA/_COMMUN/load_anim_modules/default_load_anim.swf";
  160.             }
  161.             this._loadAnim = this._moduleController.engine.getMedia({
  162.                "id":this._initParams.id + "_LOAD_ANIM",
  163.                "type":"swf",
  164.                "path":_loc1_,
  165.                "initIfNotReady":true,
  166.                "callback":this.animLoaded1
  167.             }) as MediaSwf;
  168.          }
  169.       }
  170.       
  171.       private function animLoaded1(param1:Media = null) : void
  172.       {
  173.          var _loc2_:* = this._moduleController.engine.config.modulePath + "/DATA/_COMMUN/load_bar/load_bar.swf";
  174.          this._loadBar = this._moduleController.engine.getMedia({
  175.             "id":this._initParams.id + "_LOAD_BAR",
  176.             "type":"swf",
  177.             "path":_loc2_,
  178.             "initIfNotReady":true,
  179.             "callback":this.animLoaded2
  180.          }) as MediaSwf;
  181.       }
  182.       
  183.       private function animLoaded2(param1:Media = null) : void
  184.       {
  185.          if(this._loadAnim != null)
  186.          {
  187.             this._moduleController.engine.config.layers["load_anim"].addChild(this._loadAnim.swf);
  188.             this._loadAnim.swf.gotoAndPlay(1);
  189.             this._loadAnim.swf.mouseEnabled = false;
  190.             this._loadAnim.swf.mouseChildren = false;
  191.             this._loadAnim.swf.enabled = false;
  192.          }
  193.          this._moduleController.engine.config.layers["load_anim"].addChild(this._loadBar.swf);
  194.          this._loadBar.swfContent.loadbar.gotoAndStop(1);
  195.          this._loadBar.swfContent.stage.addEventListener(Event.ENTER_FRAME,this.loadBarEnterFrameHandler);
  196.          this._mediaSwf.init(this.moduleAS3Loaded);
  197.          this._moduleController.activeModuleDestroy();
  198.       }
  199.       
  200.       private function loadBarEnterFrameHandler(param1:Event) : void
  201.       {
  202.          if(this._mediaSwf.swf != undefined)
  203.          {
  204.             this._loadBar.swfContent.loadbar.gotoAndStop(Math.floor(this._mediaSwf.swf.engine.config.loadedBytes + 1));
  205.          }
  206.       }
  207.       
  208.       private function animDestroy() : void
  209.       {
  210.          if(this._loadAnim != null)
  211.          {
  212.             this._loadAnim.swf.visible = false;
  213.             this._loadAnim.swf.gotoAndStop(1);
  214.             this._moduleController.engine.destroyMedia(this._initParams.id + "_LOAD_ANIM");
  215.             this._loadAnim = null;
  216.          }
  217.          this._loadBar.swfContent.stage.removeEventListener(Event.ENTER_FRAME,this.loadBarEnterFrameHandler);
  218.          this._loadBar.swf.visible = false;
  219.          this._loadBar.swf.gotoAndStop(1);
  220.          this._moduleController.engine.destroyMedia(this._initParams.id + "_LOAD_BAR");
  221.          this._loadBar = null;
  222.       }
  223.       
  224.       protected function moduleAS2Loaded() : void
  225.       {
  226.       }
  227.       
  228.       public function moduleIsInit() : void
  229.       {
  230.          this._callback();
  231.       }
  232.       
  233.       public function moduleIsStart() : void
  234.       {
  235.          this._callback_start();
  236.       }
  237.       
  238.       public function moduleAnimIsInit() : void
  239.       {
  240.          this._moduleController.moduleAnimIsInit();
  241.       }
  242.       
  243.       public function hostIsInitialized() : void
  244.       {
  245.          this._moduleController.hostIsInitialized();
  246.       }
  247.       
  248.       protected function moduleAS3Loaded() : void
  249.       {
  250.          this._moduleMain = this._mediaSwf.swf;
  251.          this._moduleController.moduleAnimIsInit();
  252.          this._moduleMain.init({
  253.             "context":this._moduleController.config.context,
  254.             "callback":function():void
  255.             {
  256.                _config = _mediaSwf.swf.config as Config;
  257.                _callback();
  258.             },
  259.             "initParams":{"callerParameters":this._initParams}
  260.          });
  261.       }
  262.       
  263.       public function start(param1:Function = null) : void
  264.       {
  265.          this._callback_start = param1;
  266.          if(this.asVersion == 3)
  267.          {
  268.             this._moduleMain.start();
  269.             this.animDestroy();
  270.             if(this._callback_start != null)
  271.             {
  272.                this._callback_start();
  273.             }
  274.          }
  275.          else
  276.          {
  277.             this._hostAS2.moduleStart(this._callback_start);
  278.          }
  279.       }
  280.       
  281.       public function getConfig(param1:Function) : void
  282.       {
  283.          var _loc2_:Config = null;
  284.          var _loc3_:Object = null;
  285.          this._callback_getConfig = param1;
  286.          if(this.asVersion == 3)
  287.          {
  288.             _loc2_ = this._mediaSwf.swf.config as Config;
  289.             _loc3_ = {
  290.                "id":this.id,
  291.                "rubriqueCode":_loc2_.rubriqueCode,
  292.                "moduleNum":_loc2_.moduleNum
  293.             };
  294.             this.getConfigReturn(_loc3_);
  295.          }
  296.          else
  297.          {
  298.             this._hostAS2.getModuleConfig(this.getConfigReturn);
  299.          }
  300.       }
  301.       
  302.       public function get config() : Config
  303.       {
  304.          return this._config;
  305.       }
  306.       
  307.       public function get musicOn() : Boolean
  308.       {
  309.          return this.config.musicOn;
  310.       }
  311.       
  312.       public function set musicOn(param1:Boolean) : void
  313.       {
  314.          if(this.asVersion == 3)
  315.          {
  316.             if(param1 == true)
  317.             {
  318.                this.mediaSwf.swf.engine.musicBackgroundTurnOn();
  319.             }
  320.             else
  321.             {
  322.                this.mediaSwf.swf.engine.musicBackgroundTurnOff();
  323.             }
  324.             this._hostAS2.musicOn = param1;
  325.          }
  326.          else
  327.          {
  328.             this._hostAS2.musicOn = param1;
  329.          }
  330.       }
  331.       
  332.       public function get subtitlesOn() : Boolean
  333.       {
  334.          return this.config.subtitlesOn;
  335.       }
  336.       
  337.       public function set subtitlesOn(param1:Boolean) : void
  338.       {
  339.          if(this.asVersion == 3)
  340.          {
  341.             this.mediaSwf.swf.engine.setSubtitles(param1);
  342.          }
  343.          else
  344.          {
  345.             this._hostAS2.subtitlesOn = param1;
  346.          }
  347.       }
  348.       
  349.       private function getConfigReturn(param1:Object) : void
  350.       {
  351.          this._callback_getConfig(param1);
  352.       }
  353.       
  354.       public function destroy() : void
  355.       {
  356.          if(this.asVersion == 3)
  357.          {
  358.             this._moduleMain.visible = false;
  359.             this._moduleMain.parent.removeChild(this._moduleMain);
  360.             this._mediaSwf.destroy();
  361.             this._mediaSwf = null;
  362.             this._moduleMain = null;
  363.          }
  364.          else
  365.          {
  366.             this._hostAS2.closeModule();
  367.          }
  368.       }
  369.    }
  370. }
  371.