home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 151 / MOBICLIC151.ISO / mac / DATA / SCI151 / SCI151_00 / SCI151_00.swf / scripts / sci150_00 / CapsuleAlgo.as
Text File  |  2013-01-17  |  12KB  |  358 lines

  1. package sci150_00
  2. {
  3.    import com.milanpresse.engine.text.TextBloc;
  4.    import com.milanpresse.engineaddons.facades.GameEngine;
  5.    import com.milanpresse.engineaddons.gamesprotos.actors.actorClip.IActorClip;
  6.    import com.milanpresse.tools.GlobalesFunctions;
  7.    import com.milanpresse.tools.debug.TestBox;
  8.    import flash.display.DisplayObject;
  9.    import flash.display.MovieClip;
  10.    import flash.events.TimerEvent;
  11.    import flash.geom.Point;
  12.    import flash.utils.Timer;
  13.    
  14.    public class CapsuleAlgo
  15.    {
  16.        
  17.       
  18.       protected var game:GameEngine;
  19.       
  20.       protected var generique:IActorClip;
  21.       
  22.       protected var mainTimeline:IActorClip;
  23.       
  24.       protected var testBox:TestBox;
  25.       
  26.       protected var rect:IActorClip = null;
  27.       
  28.       protected var timer:Timer;
  29.       
  30.       protected var pos:Point;
  31.       
  32.       protected var tb:TextBloc;
  33.       
  34.       protected var nuage:IActorClip;
  35.       
  36.       protected var strarr:Array;
  37.       
  38.       protected var strarrIndex:int = -1;
  39.       
  40.       protected var tbs:Vector.<TextBloc>;
  41.       
  42.       public var isSleeping:Boolean = false;
  43.       
  44.       public var isTimerSleeping:Boolean = false;
  45.       
  46.       public function CapsuleAlgo(param1:GameEngine)
  47.       {
  48.          this.timer = new Timer(100);
  49.          this.pos = new Point();
  50.          this.tbs = new Vector.<TextBloc>();
  51.          super();
  52.          this.game = param1;
  53.          this.init();
  54.       }
  55.       
  56.       protected function init() : void
  57.       {
  58.          var tab:Vector.<DisplayObject> = null;
  59.          var tab2:Vector.<DisplayObject> = null;
  60.          this.game.framerate = 24;
  61.          this.generique = this.game.addActor({
  62.             "code":"GENERIQUE",
  63.             "parent":this.game.config.layers.content
  64.          });
  65.          this.generique.getChildByName("TITRE_GENERIQUE").visible = false;
  66.          this.mainTimeline = this.game.addActor({
  67.             "code":"A_" + this.game.config.moduleName,
  68.             "parent":this.game.config.layers.content
  69.          });
  70.          this.mainTimeline.visible = false;
  71.          tab = new Vector.<DisplayObject>();
  72.          tab2 = new Vector.<DisplayObject>();
  73.          this.mainTimeline.onLabelExit = function(param1:*):void
  74.          {
  75.             tab = GlobalesFunctions.getChildrenByTypeRecursive(mainTimeline.clip,MovieClip,false,4);
  76.          };
  77.          this.mainTimeline.onLabelEnter = function(param1:*):void
  78.          {
  79.             tab2 = GlobalesFunctions.getChildrenByTypeRecursive(mainTimeline.clip,MovieClip,false,4);
  80.             var _loc2_:int = 0;
  81.             while(_loc2_ < tab.length)
  82.             {
  83.                if(tab2.indexOf(tab[_loc2_]) == -1)
  84.                {
  85.                   (tab[_loc2_] as MovieClip).stop();
  86.                }
  87.                _loc2_++;
  88.             }
  89.          };
  90.          this.mainTimeline["labelATTENTE"] = function():void
  91.          {
  92.             var btn:IActorClip = game.addActor({
  93.                "mc":mainTimeline.getChildByName("BT_REVOIR") as MovieClip,
  94.                "onRollOverState":{
  95.                   "ibId":"IB_REVOIR",
  96.                   "noiseCode":"B_REVOIR"
  97.                }
  98.             });
  99.             btn.initAs();
  100.             btn.onClick = function(param1:IActorClip):void
  101.             {
  102.                mainTimeline.gotoAndPlay(mainTimeline.currentLabels[0].name);
  103.             };
  104.             btn.enabled = true;
  105.          };
  106.          this.testBox = new TestBox(this.game.engine);
  107.          this.testBox.buttons = [{
  108.             "name":"BTN_PAUSE",
  109.             "label":"PAUSE"
  110.          },{
  111.             "name":"BTN_WAKE",
  112.             "label":"WAKE"
  113.          }];
  114.          this.testBox.onClick = function(param1:String):void
  115.          {
  116.             switch(param1)
  117.             {
  118.                case "BTN_PAUSE":
  119.                   game.sleep();
  120.                   break;
  121.                case "BTN_WAKE":
  122.                   game.wake();
  123.             }
  124.          };
  125.          this.testBox.visible = false;
  126.       }
  127.       
  128.       public function start() : void
  129.       {
  130.          this.generiqueStart();
  131.       }
  132.       
  133.       public function createRectangle(param1:Object) : MovieClip
  134.       {
  135.          var _loc2_:MovieClip = new MovieClip();
  136.          _loc2_.visible = false;
  137.          _loc2_.graphics.beginFill(param1.color == undefined ? uint(0) : uint(param1.color),param1.alpha == undefined ? Number(1) : Number(param1.alpha));
  138.          _loc2_.graphics.drawRect(param1.x == undefined ? Number(0) : Number(param1.x),param1.y == undefined ? Number(0) : Number(param1.y),param1.w == undefined ? Number(800) : Number(param1.w),param1.h == undefined ? Number(600) : Number(param1.h));
  139.          _loc2_.graphics.endFill();
  140.          return _loc2_;
  141.       }
  142.       
  143.       protected function generiqueStart() : void
  144.       {
  145.          this.generique.onLabelEnter = this.generiqueOnLabelEnter;
  146.          this.rect = this.game.addActor({
  147.             "mc":this.createRectangle({}),
  148.             "parent":this.game.config.layers.content
  149.          });
  150.          this.rect.visible = true;
  151.          this.rect.alpha = 0;
  152.          this.rect.onClick = function(param1:IActorClip):void
  153.          {
  154.             rect.enabled = false;
  155.             timer.stop();
  156.             generique.stop();
  157.             generique.destroy();
  158.             mainTimeline.visible = true;
  159.             mainTimeline.gotoAndPlay(mainTimeline.currentLabels[0].name);
  160.             game.playMusic({"code":"MU"});
  161.             rect.destroy();
  162.             rect = null;
  163.          };
  164.          this.rect.initAs();
  165.          this.generique.play("START");
  166.       }
  167.       
  168.       protected function generiqueOnLabelEnter(param1:*) : void
  169.       {
  170.          switch(param1.label)
  171.          {
  172.             case "PLAY":
  173.                this.generiqueTexteStart();
  174.                break;
  175.             case "PLAY_JINGLE":
  176.                this.game.commentPlay({
  177.                   "code":"JINGLE",
  178.                   "zapBlock":"NOZAP_NOBLOCK"
  179.                });
  180.                break;
  181.             case "FIN":
  182.                if(this.rect != null)
  183.                {
  184.                   this.rect.destroy();
  185.                }
  186.                this.generique.stop();
  187.                this.generique.destroy();
  188.                this.mainTimeline.visible = true;
  189.                this.game.playMusic({"code":"MU"});
  190.                this.mainTimeline.gotoAndPlay(this.mainTimeline.currentLabels[0].name);
  191.          }
  192.       }
  193.       
  194.       public function generiqueTexteStart() : void
  195.       {
  196.          var _loc5_:int = 0;
  197.          var _loc9_:int = 0;
  198.          var _loc10_:int = 0;
  199.          var _loc1_:MovieClip = this.generique.getChildByName("TITRE_GENERIQUE") as MovieClip;
  200.          _loc1_.visible = false;
  201.          this.pos.y = _loc1_.y;
  202.          this.pos.x = _loc1_.x;
  203.          var _loc2_:int = 1;
  204.          var _loc3_:Boolean = false;
  205.          this.strarr = this.game.getMediaText({"id":"LM_TITRE"}).text.split(" ");
  206.          var _loc4_:int = 0;
  207.          while(_loc4_ < this.strarr.length)
  208.          {
  209.             _loc3_ = false;
  210.             if(this.strarr[_loc4_].search(/┬º$/) != -1)
  211.             {
  212.                _loc3_ = true;
  213.                this.strarr[_loc4_] = (this.strarr[_loc4_] as String).slice(0,-1);
  214.             }
  215.             this.tb = this.game.showTextBloc({
  216.                "text":this.strarr[_loc4_],
  217.                "idStyle":"LM.LM_TITRE",
  218.                "parent":_loc1_.parent
  219.             });
  220.             this.generique.clip.addChildAt(this.tb,this.generique.clip.getChildIndex(_loc1_));
  221.             this.tb.visible = false;
  222.             this.tb.x = this.pos.x;
  223.             this.tb.y = this.pos.y;
  224.             this.tb["row"] = _loc2_;
  225.             this.pos.x += this.tb.width + 5;
  226.             if(this.pos.x > _loc1_.x + _loc1_.width)
  227.             {
  228.                this.pos.x = _loc1_.x + this.tb.width + 5;
  229.                this.pos.y += this.tb.height + 5;
  230.                this.tb.x = _loc1_.x;
  231.                this.tb.y = this.pos.y;
  232.                _loc2_++;
  233.                this.tb["row"] = _loc2_;
  234.             }
  235.             if(_loc3_ == true)
  236.             {
  237.                this.pos.x = _loc1_.x;
  238.                this.pos.y += this.tb.height + 5;
  239.                _loc2_++;
  240.             }
  241.             this.tbs.push(this.tb);
  242.             _loc4_++;
  243.          }
  244.          _loc5_ = 0;
  245.          while(_loc5_ < this.tbs.length)
  246.          {
  247.             _loc5_++;
  248.          }
  249.          var _loc6_:Number = 0;
  250.          var _loc7_:Number = 0;
  251.          var _loc8_:int = 1;
  252.          while(_loc8_ <= _loc2_)
  253.          {
  254.             _loc6_ = 0;
  255.             _loc7_ = 0;
  256.             _loc9_ = 0;
  257.             while(_loc9_ < this.tbs.length)
  258.             {
  259.                if(this.tbs[_loc9_]["row"] == _loc8_)
  260.                {
  261.                   _loc6_ += this.tbs[_loc9_].width + 5;
  262.                }
  263.                _loc9_++;
  264.             }
  265.             _loc7_ = (_loc1_.width - _loc6_) / 2;
  266.             _loc10_ = 0;
  267.             while(_loc10_ < this.tbs.length)
  268.             {
  269.                if(this.tbs[_loc10_]["row"] == _loc8_)
  270.                {
  271.                   this.tbs[_loc10_].x += _loc7_;
  272.                }
  273.                _loc10_++;
  274.             }
  275.             _loc8_++;
  276.          }
  277.          _loc5_ = 0;
  278.          while(_loc5_ < this.tbs.length)
  279.          {
  280.             _loc5_++;
  281.          }
  282.          this.timer.addEventListener(TimerEvent.TIMER,this.onTimer);
  283.          this.timer.start();
  284.       }
  285.       
  286.       public function onTimer(param1:TimerEvent) : void
  287.       {
  288.          var nuage:IActorClip = null;
  289.          var event:TimerEvent = param1;
  290.          ++this.strarrIndex;
  291.          if(this.strarrIndex > this.strarr.length - 1)
  292.          {
  293.             this.timer.stop();
  294.             this.timer.removeEventListener(TimerEvent.TIMER,this.onTimer);
  295.          }
  296.          else
  297.          {
  298.             nuage = this.game.addActor({
  299.                "mc":new NUAGE_PETIT(),
  300.                "parent":this.generique.clip
  301.             });
  302.             nuage["tb"] = this.tbs[this.strarrIndex];
  303.             nuage.onFrameExit = function(param1:* = null):void
  304.             {
  305.                if(this.currentFrame == 8)
  306.                {
  307.                   nuage["tb"].visible = true;
  308.                }
  309.                if(this.currentFrame == this.totalFrames)
  310.                {
  311.                   this.destroy();
  312.                }
  313.             };
  314.             nuage.x = this.tbs[this.strarrIndex].x + this.tbs[this.strarrIndex].width / 2;
  315.             nuage.y = this.tbs[this.strarrIndex].y + this.tbs[this.strarrIndex].height / 2;
  316.             nuage.play(1);
  317.          }
  318.       }
  319.       
  320.       public function sleep() : void
  321.       {
  322.          if(this.isSleeping)
  323.          {
  324.             return;
  325.          }
  326.          this.isSleeping = true;
  327.          if(this.timer.running)
  328.          {
  329.             this.isTimerSleeping = true;
  330.             this.timer.stop();
  331.          }
  332.       }
  333.       
  334.       public function wake() : void
  335.       {
  336.          if(this.isSleeping == false)
  337.          {
  338.             return;
  339.          }
  340.          this.isSleeping = false;
  341.          if(this.isTimerSleeping)
  342.          {
  343.             this.isTimerSleeping = false;
  344.             this.timer.start();
  345.          }
  346.       }
  347.       
  348.       public function destroy() : void
  349.       {
  350.          if(this.timer != null)
  351.          {
  352.             this.timer.stop();
  353.             this.timer.removeEventListener(TimerEvent.TIMER,this.onTimer);
  354.          }
  355.       }
  356.    }
  357. }
  358.