home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 150 / MOBICLIC150.ISO / pc / DATA / DSS150 / DSS150_01 / DSS150_01.swf / scripts / dss150_01 / ATTENTE.as next >
Text File  |  2012-12-19  |  5KB  |  188 lines

  1. package dss150_01
  2. {
  3.    import com.milanpresse.engineaddons.facades.GameEngine;
  4.    import com.milanpresse.engineaddons.gamesprotos.Actor;
  5.    import com.milanpresse.engineaddons.gamesprotos.actors.actorClip.IActorClip;
  6.    import com.milanpresse.engineaddons.timers.TimerChild;
  7.    import flash.display.MovieClip;
  8.    import flash.ui.Mouse;
  9.    
  10.    public class ATTENTE
  11.    {
  12.        
  13.       
  14.       private var game:GameEngine;
  15.       
  16.       public var onEvent:Function = null;
  17.       
  18.       private var _container:IActorClip;
  19.       
  20.       private var attente:Actor;
  21.       
  22.       private var timerIsOn:TimerChild;
  23.       
  24.       private var timerRelance:TimerChild;
  25.       
  26.       private var torche:IActorClip;
  27.       
  28.       private var faisceau:IActorClip;
  29.       
  30.       private var morceau:IActorClip;
  31.       
  32.       private var _mouseVisible:Boolean = true;
  33.       
  34.       protected var isSleeping:Boolean = false;
  35.       
  36.       protected var sleepState:Object;
  37.       
  38.       public function ATTENTE(game:GameEngine, container:IActorClip)
  39.       {
  40.          var clip:IActorClip = null;
  41.          this.sleepState = {"mouseVisible":true};
  42.          super();
  43.          this.game = game;
  44.          this._container = container;
  45.          this.attente = game.addActor(new Actor(game));
  46.          this.attente.name = "ATTENTE";
  47.          this.torche = this.attente.addActor({"mc":this._container.getChildByName("DECOR.LUZ") as MovieClip});
  48.          clip = this.attente.addActor({"mc":this._container.getChildByName("DECOR.CERCLE") as MovieClip});
  49.          clip.initAs();
  50.          clip.dragEnabled = true;
  51.          clip.enabled = false;
  52.          this.morceau = this.attente.addActor({"mc":this._container.getChildByName("ZONE") as MovieClip});
  53.          clip.dragDrop.dropTargets = [this.morceau];
  54.          clip.onDrag = this.onDrag;
  55.          this.faisceau = clip;
  56.          this.faisceau.limitZone = {
  57.             "x":0,
  58.             "y":0,
  59.             "width":game.stage.stageWidth,
  60.             "height":game.stage.stageHeight
  61.          };
  62.          this.timerRelance = game.mainTimer.addFromObj({
  63.             "id":"timerRelance",
  64.             "delay":game.moduleConfig.relanceDelayMS,
  65.             "loop":1,
  66.             "onDelay":function(tc:TimerChild):void
  67.             {
  68.                game.commentPlay({
  69.                   "code":"JEU_AIDE",
  70.                   "callback":function():void
  71.                   {
  72.                      timerRelance.reset();
  73.                      timerRelance.start();
  74.                   }
  75.                });
  76.             }
  77.          });
  78.          this.timerIsOn = game.mainTimer.addFromObj({
  79.             "id":"timerIsOn",
  80.             "delay":game.moduleConfig.TrouveDelayMS,
  81.             "loop":1,
  82.             "onDelay":function(tc:TimerChild):void
  83.             {
  84.                finish();
  85.             }
  86.          });
  87.          this.mouseVisible = false;
  88.          game.mainTimer.start();
  89.          this.faisceau.dragStart();
  90.       }
  91.       
  92.       public function get mouseVisible() : Boolean
  93.       {
  94.          return this._mouseVisible;
  95.       }
  96.       
  97.       public function set mouseVisible(value:Boolean) : void
  98.       {
  99.          if(value == true)
  100.          {
  101.             Mouse.show();
  102.          }
  103.          else
  104.          {
  105.             Mouse.hide();
  106.          }
  107.          this._mouseVisible = value;
  108.       }
  109.       
  110.       private function onDrag(actor:IActorClip) : void
  111.       {
  112.          if(this.isSleeping)
  113.          {
  114.             return;
  115.          }
  116.          this.faisceau.setToPos(this.game.stage.mouseX,this.game.stage.mouseY);
  117.          this.torche.x = this.faisceau.x;
  118.          this.torche.y = this.faisceau.y;
  119.          if(actor.dragDrop.dropTarget != null)
  120.          {
  121.             if(this.timerIsOn.running == false)
  122.             {
  123.                this.timerIsOn.reset();
  124.                this.timerIsOn.start();
  125.             }
  126.          }
  127.          else
  128.          {
  129.             this.timerIsOn.stop();
  130.          }
  131.       }
  132.       
  133.       protected function stop() : void
  134.       {
  135.          if(this.attente != null)
  136.          {
  137.             this.faisceau.dragStop();
  138.             this.game.commentStop();
  139.             this.timerRelance.stop();
  140.             this.timerIsOn.stop();
  141.             this.mouseVisible = true;
  142.          }
  143.       }
  144.       
  145.       private function finish() : void
  146.       {
  147.          trace("finish");
  148.          this.destroy();
  149.          if(this.onEvent != null)
  150.          {
  151.             this.onEvent({"action":"succes"});
  152.          }
  153.       }
  154.       
  155.       public function sleep() : void
  156.       {
  157.          if(this.isSleeping)
  158.          {
  159.             return;
  160.          }
  161.          this.isSleeping = true;
  162.          this.sleepState.mouseVisible = this._mouseVisible;
  163.          this.mouseVisible = true;
  164.       }
  165.       
  166.       public function wake() : void
  167.       {
  168.          if(this.isSleeping == false)
  169.          {
  170.             return;
  171.          }
  172.          this.isSleeping = false;
  173.          this.mouseVisible = this.sleepState.mouseVisible;
  174.       }
  175.       
  176.       public function destroy() : void
  177.       {
  178.          this.stop();
  179.          if(this.attente != null)
  180.          {
  181.             this.attente.dissociate();
  182.             this.attente.destroy();
  183.          }
  184.          this.attente = null;
  185.       }
  186.    }
  187. }
  188.