home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 155 / MOBICLIC155.ISO / mac / DATA / DSS155 / DSS155_01 / MOD149_00.swf / scripts / mod149_00 / MainAlgo.as
Text File  |  2013-07-08  |  14KB  |  346 lines

  1. package mod149_00
  2. {
  3.    import com.milanpresse.engine.medias.MediaImage;
  4.    import com.milanpresse.engine.medias.MediaTexte;
  5.    import com.milanpresse.engineaddons.facades.GameEngine;
  6.    import com.milanpresse.engineaddons.gamesprotos.Actor;
  7.    import com.milanpresse.engineaddons.gamesprotos.actors.actorClip.ActorClip;
  8.    import com.milanpresse.engineaddons.gamesprotos.actors.actorClip.IActorClip;
  9.    import com.milanpresse.tools.GlobalesFunctions;
  10.    import flash.display.MovieClip;
  11.    
  12.    public dynamic class MainAlgo
  13.    {
  14.        
  15.       
  16.       private var _e:GameEngine;
  17.       
  18.       public var mainTimeline:IActorClip;
  19.       
  20.       public var interfaceGroup:Actor;
  21.       
  22.       public function MainAlgo(game:GameEngine)
  23.       {
  24.          super();
  25.          this._e = game;
  26.          this._e.levelCZ = this._e.config.layers.content;
  27.          this.mainTimeline = this._e.addActor({
  28.             "code":"A_" + this._e.config.moduleName,
  29.             "parent":this._e.config.layers.content
  30.          });
  31.          this.mainTimeline.onLabelEnter = this.onEachLabel;
  32.          this.mainTimeline.onLabelExit = this.onLabelExit;
  33.       }
  34.       
  35.       public function start() : void
  36.       {
  37.          this.mainTimeline.gotoAndPlay(this.mainTimeline.currentLabels[0].name);
  38.       }
  39.       
  40.       public function onEachLabel(result:Object = null) : void
  41.       {
  42.          trace("onEachLabel",this.mainTimeline.currentLabel);
  43.          this.interfaceGroup = this._e.addActor(new Actor(this._e));
  44.          this.interfaceGroup.name = "interfaceGroupe";
  45.          switch(this.mainTimeline.currentLabel)
  46.          {
  47.             case "_E_0" + this._e.memo.etapeEnCours + "_01":
  48.                this._E_XX_01();
  49.                break;
  50.             case "_E_0" + this._e.memo.etapeEnCours + "_FIN":
  51.                this._e.memo.quizListAlea = GlobalesFunctions.randomArray([1,2,3,4]);
  52.                this.quizInit();
  53.                break;
  54.             case "ATTENTE_0" + this._e.memo.etapeEnCours:
  55.             case "_E_0" + this._e.memo.etapeEnCours + "_SUCCES":
  56.             case "_E_0" + this._e.memo.etapeEnCours + "_ECHEC":
  57.                this.quizInit();
  58.          }
  59.          this.setPhotoIfExists();
  60.          this.interfaceShow();
  61.       }
  62.       
  63.       public function onLabelExit(result:Object = null) : void
  64.       {
  65.          trace("onLabelExit",result.label);
  66.          if(this.interfaceGroup != null)
  67.          {
  68.             this.interfaceGroup.foreach(function(actor:Actor):void
  69.             {
  70.                (actor as ActorClip).restore();
  71.                (actor as ActorClip).dissociate();
  72.             });
  73.             this.interfaceGroup.destroy();
  74.          }
  75.       }
  76.       
  77.       public function interfaceShow() : void
  78.       {
  79.          var clip:IActorClip = null;
  80.          if(this.mainTimeline.getChildByName("PERSO") != null)
  81.          {
  82.             clip = this.interfaceGroup.addActor({"mc":this.mainTimeline.getChildByName("PERSO") as MovieClip});
  83.             clip.initAs();
  84.             clip.enabled = false;
  85.          }
  86.          if(this.mainTimeline.getChildByName("BT_FERMER_CONT.BT_FERMER") != null)
  87.          {
  88.             clip = this.interfaceGroup.addActor({
  89.                "mc":this.mainTimeline.getChildByName("BT_FERMER_CONT.BT_FERMER") as MovieClip,
  90.                "onRollOverState":{"noiseCode":"B_FERME"}
  91.             });
  92.             clip.parent = this._e.config.layers.menu;
  93.             clip.x = this.mainTimeline.getChildByName("BT_FERMER_CONT").x;
  94.             clip.y = this.mainTimeline.getChildByName("BT_FERMER_CONT").y;
  95.             clip.initAs();
  96.             clip.onClick = function(actor:ActorClip):void
  97.             {
  98.                trace("click",actor,this);
  99.                _e.engine.stopComment();
  100.                mainTimeline.gotoAndStop("ATTENTE");
  101.             };
  102.             clip.enabled = true;
  103.             clip.visible = true;
  104.          }
  105.          for(var i:int = 1; i <= 3; i++)
  106.          {
  107.             if(this.mainTimeline.getChildByName("EXP_0" + i) != null)
  108.             {
  109.                clip = this.interfaceGroup.addActor({
  110.                   "mc":this.mainTimeline.getChildByName("EXP_0" + i) as MovieClip,
  111.                   "onRollOverState":{
  112.                      "ibId":"IB_E_0" + i,
  113.                      "ibRef":{"position":12},
  114.                      "noiseCode":"B0" + i
  115.                   }
  116.                });
  117.                clip["no"] = i;
  118.                clip.initAs();
  119.                clip.onClick = function(actor:ActorClip):void
  120.                {
  121.                   trace("click",actor,this);
  122.                   _e.memo.etapeEnCours = actor["no"];
  123.                   mainTimeline.gotoAndPlay("_E_0" + _e.memo.etapeEnCours + "_01",{"labelLastCallback":function():void
  124.                   {
  125.                      (interfaceGroup.getActor("PERSO") as ActorClip).gotoAndStop("E2");
  126.                   }});
  127.                };
  128.                clip.enabled = true;
  129.             }
  130.             if(this.mainTimeline.getChildByName("BT_DEC_0" + i) != null)
  131.             {
  132.                clip = this.interfaceGroup.addActor({
  133.                   "mc":this.mainTimeline.getChildByName("BT_DEC_0" + i) as MovieClip,
  134.                   "no":i,
  135.                   "onRollOverState":{
  136.                      "ibId":"IB0" + i,
  137.                      "ibRef":{"position":6},
  138.                      "noiseCode":"B_DEC"
  139.                   }
  140.                });
  141.                clip["no"] = i;
  142.                clip.initAs();
  143.                clip.onClick = function(actor:ActorClip):void
  144.                {
  145.                   trace("click",actor,this);
  146.                   _e.memo.etapeEnCours = actor["no"];
  147.                   mainTimeline.gotoAndPlay("_0" + _e.memo.etapeEnCours + "_01",{
  148.                      "labelLast":"_0" + _e.memo.etapeEnCours + "_FIN",
  149.                      "labelLastCallback":function():void
  150.                      {
  151.                         mainTimeline.gotoAndStop("ATTENTE");
  152.                      }
  153.                   });
  154.                };
  155.                if(this._e.memo["vu" + i] != true)
  156.                {
  157.                   clip.visible = false;
  158.                }
  159.                else
  160.                {
  161.                   clip.visible = true;
  162.                }
  163.                if(this.mainTimeline.currentLabel != "ATTENTE")
  164.                {
  165.                   if(i == this._e.memo.etapeEnCours)
  166.                   {
  167.                      clip.gotoAndStop("E3");
  168.                   }
  169.                   else
  170.                   {
  171.                      clip.gotoAndStop("E1");
  172.                   }
  173.                   clip.enabled = false;
  174.                }
  175.                else
  176.                {
  177.                   clip.enabled = true;
  178.                }
  179.             }
  180.          }
  181.       }
  182.       
  183.       public function _E_XX_01() : void
  184.       {
  185.          var texteMedia:MediaTexte = this._e.getMediaText({"id":"LM0" + this._e.memo.etapeEnCours});
  186.          var target:MovieClip = this.mainTimeline.getChildByName("LMXX") as MovieClip;
  187.          if(target != null && texteMedia != null)
  188.          {
  189.             this._e.showTextBloc({
  190.                "text":texteMedia.text.split("┬º").join("\n"),
  191.                "target":target.TEXTE,
  192.                "idStyle":"LM.LM_MATERIEL"
  193.             });
  194.             target.TEXTE.border = false;
  195.          }
  196.       }
  197.       
  198.       public function quizInit() : void
  199.       {
  200.          var texteMedia:MediaTexte = null;
  201.          var target:MovieClip = null;
  202.          var zone:ActorClip = null;
  203.          for(var j:int = 1; j <= 4; j++)
  204.          {
  205.             texteMedia = this._e.getMediaText({"id":"LM_E_0" + this._e.memo.etapeEnCours + "_0" + this._e.memo.quizListAlea[j - 1]});
  206.             target = this.mainTimeline.getChildByName("QUIZ_LMS.LM_E_XX_0" + j) as MovieClip;
  207.             if(target != null && texteMedia != null)
  208.             {
  209.                this._e.showTextBloc({
  210.                   "text":texteMedia.text,
  211.                   "target":target.TEXTE,
  212.                   "idStyle":"LM.LM_REPONSE"
  213.                });
  214.                target.TEXTE.border = false;
  215.             }
  216.             zone = this.interfaceGroup.addActor({"mc":target});
  217.             zone.initAs();
  218.             zone.noReponse = this._e.memo.quizListAlea[j - 1];
  219.             zone.onClick = function(actor:ActorClip):void
  220.             {
  221.                trace("click",actor,this);
  222.                if(actor.noReponse == 1)
  223.                {
  224.                   _e.memo["vu" + _e.memo.etapeEnCours] = true;
  225.                   mainTimeline.gotoAndPlay("_E_0" + _e.memo.etapeEnCours + "_SUCCES",{"labelLastCallback":function():void
  226.                   {
  227.                      mainTimeline.gotoAndStop("ATTENTE");
  228.                   }});
  229.                }
  230.                else
  231.                {
  232.                   mainTimeline.gotoAndPlay("_E_0" + _e.memo.etapeEnCours + "_ECHEC",{"labelLastCallback":function():void
  233.                   {
  234.                      mainTimeline.gotoAndStop("ATTENTE_0" + _e.memo.etapeEnCours);
  235.                   }});
  236.                }
  237.             };
  238.             if(this.mainTimeline.currentLabel == "_E_0" + this._e.memo.etapeEnCours + "_SUCCES")
  239.             {
  240.                zone.enabled = false;
  241.                if(zone.noReponse == 1)
  242.                {
  243.                   zone.gotoAndStop("E2");
  244.                }
  245.             }
  246.             else if(this.mainTimeline.currentLabel == "ATTENTE_0" + this._e.memo.etapeEnCours)
  247.             {
  248.                zone.enabled = true;
  249.                zone.gotoAndStop("E1");
  250.             }
  251.             else
  252.             {
  253.                zone.enabled = false;
  254.                zone.gotoAndStop("E1");
  255.             }
  256.          }
  257.       }
  258.       
  259.       public function setPhotoIfExists() : void
  260.       {
  261.          var noSousEtape:int = 0;
  262.          var photoLast:MediaImage = null;
  263.          var zone:ActorClip = null;
  264.          var photoCode:String = this.mainTimeline.currentLabel.search(/^_E/) != -1 ? this.mainTimeline.currentLabel.replace("_E","PH") : this.mainTimeline.currentLabel.replace("_","PH_");
  265.          noSousEtape = int(this.mainTimeline.currentLabel.split("_")[3]);
  266.          if(this._e.getMediaImage(photoCode) != null && this.mainTimeline.getChildByName("PHOTO") != null)
  267.          {
  268.             trace("photo",photoCode);
  269.             photoLast = this._e.showImage({
  270.                "code":photoCode,
  271.                "parent":this.mainTimeline.getChildByName("PHOTO")
  272.             });
  273.             if(this.mainTimeline.getChildByName("FLECHES_CONT.BT_REC") != null)
  274.             {
  275.                zone = this.interfaceGroup.addActor({
  276.                   "mc":this.mainTimeline.getChildByName("FLECHES_CONT.BT_REC") as MovieClip,
  277.                   "onRollOverState":{"noiseCode":"B_REC"}
  278.                });
  279.                zone.initAs();
  280.                zone.parent = this._e.config.layers.menu;
  281.                zone.x += this.mainTimeline.getChildByName("FLECHES_CONT").x;
  282.                zone.y += this.mainTimeline.getChildByName("FLECHES_CONT").y;
  283.                zone.onClick = function(actor:ActorClip):void
  284.                {
  285.                   trace("click",actor,this);
  286.                   mainTimeline.gotoAndPlay("_E_0" + _e.memo.etapeEnCours + "_0" + int(noSousEtape - 1),{"labelLastCallback":function():void
  287.                   {
  288.                      (interfaceGroup.getActor("PERSO") as ActorClip).gotoAndStop("E2");
  289.                   }});
  290.                };
  291.                if(this.mainTimeline.hasLabel("_E_0" + this._e.memo.etapeEnCours + "_0" + int(noSousEtape - 1)))
  292.                {
  293.                   zone.enabled = true;
  294.                }
  295.                else
  296.                {
  297.                   zone.enabled = false;
  298.                   zone.gotoAndStop("E0");
  299.                }
  300.                zone = this.interfaceGroup.addActor({
  301.                   "mc":this.mainTimeline.getChildByName("FLECHES_CONT.BT_AV"),
  302.                   "onRollOverState":{"noiseCode":"B_AV"}
  303.                });
  304.                zone.initAs();
  305.                zone.onClick = function(actor:ActorClip):void
  306.                {
  307.                   trace("click",actor,this);
  308.                   if(mainTimeline.hasLabel("_E_0" + _e.memo.etapeEnCours + "_0" + int(noSousEtape + 1)))
  309.                   {
  310.                      zone.nextLabel = "_E_0" + _e.memo.etapeEnCours + "_0" + int(noSousEtape + 1);
  311.                      mainTimeline.gotoAndPlay(actor.nextLabel,{"labelLastCallback":function():void
  312.                      {
  313.                         (interfaceGroup.getActor("PERSO") as ActorClip).gotoAndStop("E2");
  314.                      }});
  315.                   }
  316.                   else
  317.                   {
  318.                      zone.nextLabel = "_E_0" + _e.memo.etapeEnCours + "_FIN";
  319.                      mainTimeline.gotoAndPlay(actor.nextLabel);
  320.                   }
  321.                };
  322.                zone.parent = this._e.config.layers.menu;
  323.                zone.x += this.mainTimeline.getChildByName("FLECHES_CONT").x;
  324.                zone.y += this.mainTimeline.getChildByName("FLECHES_CONT").y;
  325.                zone.enabled = true;
  326.             }
  327.          }
  328.       }
  329.       
  330.       public function sleep() : void
  331.       {
  332.          this._e.sleep();
  333.       }
  334.       
  335.       public function wake() : void
  336.       {
  337.          this._e.wake();
  338.       }
  339.       
  340.       public function destroy() : void
  341.       {
  342.          this._e.destroy();
  343.       }
  344.    }
  345. }
  346.