home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 161 / MOBICLIC161.ISO / pc / DATA / DSS161 / DSS161_00 / DSS161_00.swf / scripts / dss161_00 / AppareilPhoto.as next >
Text File  |  2014-01-15  |  6KB  |  169 lines

  1. package dss161_00
  2. {
  3.    import dss161.engineaddons.gamesprotos.Actor;
  4.    import dss161.engineaddons.gamesprotos.actors.actorClip.ActorClip;
  5.    import flash.display.Bitmap;
  6.    import flash.display.BitmapData;
  7.    import flash.events.MouseEvent;
  8.    import flash.geom.Point;
  9.    import flash.geom.Rectangle;
  10.    import flash.text.TextField;
  11.    import flash.ui.Mouse;
  12.    
  13.    public class AppareilPhoto extends Actor
  14.    {
  15.        
  16.       
  17.       private var actorClip:ActorClip;
  18.       
  19.       public var visual:ActorClip;
  20.       
  21.       private var onEvent:Function;
  22.       
  23.       private var viseur:ActorClip;
  24.       
  25.       public function AppareilPhoto(param1:* = null)
  26.       {
  27.          var params:* = param1;
  28.          super();
  29.          this.onEvent = params.onEvent;
  30.          if(game.captures == undefined)
  31.          {
  32.             game.captures = [0,0,0,0,0,0,0,0,0,0];
  33.          }
  34.          game.numCaptures = 0;
  35.          var i:int = 0;
  36.          while(i < game.captures.length)
  37.          {
  38.             if(game.captures[i] != 0)
  39.             {
  40.                ++game.numCaptures;
  41.             }
  42.             i++;
  43.          }
  44.          this.visual = addActor({"mc":params.visualMC});
  45.          this.visual.actif = true;
  46.          this.visual.limitZone = new Rectangle(-61,-145,1016,767);
  47.          this.visual.onDrag = function(param1:ActorClip):void
  48.          {
  49.             if(visual.actif)
  50.             {
  51.                if(game.stage.mouseX < 200 && game.stage.mouseY > 400)
  52.                {
  53.                   Mouse.show();
  54.                }
  55.                else
  56.                {
  57.                   Mouse.hide();
  58.                }
  59.                param1.setToPos(game.stage.mouseX,game.stage.mouseY,"CENTER");
  60.             }
  61.          };
  62.          this.visual.dragEnabled = true;
  63.          this.visual.enabled = false;
  64.          this.visual.initAs();
  65.          this.visual.dragStart();
  66.          if(game.engine.pad != null)
  67.          {
  68.          }
  69.          this.viseur = addActor({"mc":this.visual.getChildByName("VISEUR")});
  70.          game.showTextBloc({
  71.             "text":game.numCaptures + "/10",
  72.             "target":this.viseur.getChildByName("LM_COMPTEUR.TEXTE") as TextField,
  73.             "idStyle":"LM.LM_PHOTO"
  74.          });
  75.          game.stage.addEventListener(MouseEvent.MOUSE_DOWN,this.onClickHandler);
  76.          Mouse.hide();
  77.       }
  78.       
  79.       private function onClickHandler(param1:MouseEvent) : void
  80.       {
  81.          game.stage.removeEventListener(MouseEvent.MOUSE_DOWN,this.onClickHandler);
  82.          this.visual.dragStop();
  83.          this.visual.visible = false;
  84.          this.capture();
  85.       }
  86.       
  87.       private function onUpHandler(param1:MouseEvent) : void
  88.       {
  89.          game.stage.removeEventListener(MouseEvent.MOUSE_UP,this.onUpHandler);
  90.          this.visual.dragStart();
  91.          game.stage.addEventListener(MouseEvent.MOUSE_DOWN,this.onClickHandler);
  92.       }
  93.       
  94.       private function capture() : void
  95.       {
  96.          var _loc1_:Rectangle = null;
  97.          game.noisePlay({"code":"B_PHOTO"});
  98.          var _loc2_:Point = new Point(this.viseur.x,this.viseur.y);
  99.          var _loc3_:Point = new Point(this.viseur.x + this.viseur.width,this.viseur.y + this.viseur.height);
  100.          _loc2_ = this.visual.clip.localToGlobal(_loc2_);
  101.          _loc3_ = this.visual.clip.localToGlobal(_loc3_);
  102.          _loc1_ = new Rectangle(_loc2_.x,_loc2_.y,_loc3_.x - _loc2_.x,_loc3_.y - _loc2_.y);
  103.          var _loc4_:BitmapData = new BitmapData(800,600,false);
  104.          _loc4_.draw(game.stage,null,null,null,_loc1_);
  105.          var _loc5_:BitmapData = new BitmapData(_loc1_.width,_loc1_.height,false);
  106.          _loc5_.copyPixels(_loc4_,_loc1_,new Point(0,0));
  107.          var _loc6_:Bitmap = new Bitmap(_loc5_,"auto",true);
  108.          game.numCaptures = 0;
  109.          var _loc7_:Boolean = false;
  110.          var _loc8_:int = 0;
  111.          while(_loc8_ < game.captures.length)
  112.          {
  113.             if(!_loc7_ && game.captures[_loc8_] == 0)
  114.             {
  115.                _loc7_ = true;
  116.                game.captures[_loc8_] = _loc6_;
  117.             }
  118.             if(game.captures[_loc8_] != 0)
  119.             {
  120.                ++game.numCaptures;
  121.             }
  122.             _loc8_++;
  123.          }
  124.          game.showTextBloc({
  125.             "text":game.numCaptures + "/10",
  126.             "target":this.viseur.getChildByName("LM_COMPTEUR.TEXTE") as TextField,
  127.             "idStyle":"LM.LM_PHOTO"
  128.          });
  129.          if(game.numCaptures >= 10)
  130.          {
  131.             this._destroy();
  132.             if(game.engine.pad != null)
  133.             {
  134.                game.engine.pad.activated = true;
  135.             }
  136.             this.onEvent();
  137.          }
  138.          else
  139.          {
  140.             game.stage.addEventListener(MouseEvent.MOUSE_UP,this.onUpHandler);
  141.             this.visual.visible = true;
  142.          }
  143.       }
  144.       
  145.       override protected function _sleep() : void
  146.       {
  147.          this.visual.actif = false;
  148.          game.stage.removeEventListener(MouseEvent.MOUSE_UP,this.onUpHandler);
  149.          game.stage.removeEventListener(MouseEvent.MOUSE_DOWN,this.onClickHandler);
  150.          Mouse.show();
  151.       }
  152.       
  153.       override protected function _wake() : void
  154.       {
  155.          this.visual.actif = true;
  156.          Mouse.hide();
  157.          game.stage.addEventListener(MouseEvent.MOUSE_DOWN,this.onClickHandler);
  158.       }
  159.       
  160.       override protected function _destroy() : void
  161.       {
  162.          super._destroy();
  163.          Mouse.show();
  164.          game.stage.removeEventListener(MouseEvent.MOUSE_UP,this.onUpHandler);
  165.          game.stage.removeEventListener(MouseEvent.MOUSE_DOWN,this.onClickHandler);
  166.       }
  167.    }
  168. }
  169.