home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Aventura / climatechaos.swf / scripts / __Packages / DigiCam.as < prev    next >
Encoding:
Text File  |  2008-09-12  |  8.1 KB  |  295 lines

  1. class DigiCam extends MovieClip
  2. {
  3.    var current_photo_num;
  4.    var save;
  5.    var save_photo;
  6.    var env;
  7.    var current_photo;
  8.    var touch_side;
  9.    var screen;
  10.    var photo;
  11.    var replacement;
  12.    var onEnterFrame;
  13.    function DigiCam()
  14.    {
  15.       super();
  16.       AsBroadcaster.initialize(this);
  17.       this.current_photo_num = 0;
  18.       this.save = new Object();
  19.       this.save.photos = [];
  20.       var _loc3_ = 0;
  21.       while(_loc3_ < 9)
  22.       {
  23.          this.save.photos[_loc3_] = {};
  24.          this.save.photos[_loc3_].object_id = undefined;
  25.          this.save.photos[_loc3_].image = new flash.display.BitmapData(225,140,false,0);
  26.          _loc3_ = _loc3_ + 1;
  27.       }
  28.       this.save_photo = {};
  29.       this.save_photo.image = new flash.display.BitmapData(225,140,false,0);
  30.    }
  31.    function setEnvironment(p_env)
  32.    {
  33.       this.env = p_env;
  34.    }
  35.    function loadSave()
  36.    {
  37.       var _loc3_ = SharedObject.getLocal("BRCCSaveData");
  38.       this.save.photos = [];
  39.       var _loc2_ = 0;
  40.       while(_loc2_ < 9)
  41.       {
  42.          this.save.photos[_loc2_] = {};
  43.          this.save.photos[_loc2_].object_id = _loc3_.data.photos[_loc2_].object_id;
  44.          this.save.photos[_loc2_].image = this.saveToImage(_loc3_.data.photos[_loc2_].image);
  45.          _loc2_ = _loc2_ + 1;
  46.       }
  47.    }
  48.    function writeSave()
  49.    {
  50.       var _loc3_ = SharedObject.getLocal("BRCCSaveData");
  51.       _loc3_.data.photos = [];
  52.       var _loc2_ = 0;
  53.       while(_loc2_ < 9)
  54.       {
  55.          _loc3_.data.photos[_loc2_] = {};
  56.          _loc3_.data.photos[_loc2_].object_id = this.save.photos[_loc2_].object_id;
  57.          _loc3_.data.photos[_loc2_].image = this.imageToSave(this.save.photos[_loc2_].image);
  58.          _loc2_ = _loc2_ + 1;
  59.       }
  60.       _loc3_.flush();
  61.    }
  62.    function imageToSave(p_image)
  63.    {
  64.       var _loc4_ = [];
  65.       var _loc2_ = 0;
  66.       while(_loc2_ < p_image.height)
  67.       {
  68.          _loc4_[_loc2_] = [];
  69.          var _loc1_ = 0;
  70.          while(_loc1_ < p_image.width)
  71.          {
  72.             _loc4_[_loc2_][_loc1_] = p_image.getPixel(_loc1_,_loc2_);
  73.             _loc1_ = _loc1_ + 1;
  74.          }
  75.          _loc2_ = _loc2_ + 1;
  76.       }
  77.       return _loc4_;
  78.    }
  79.    function saveToImage(p_save)
  80.    {
  81.       var _loc5_ = p_save.length;
  82.       var _loc3_ = new flash.display.BitmapData(225,_loc5_,false,0);
  83.       var _loc2_ = 0;
  84.       while(_loc2_ < _loc3_.height)
  85.       {
  86.          var _loc1_ = 0;
  87.          while(_loc1_ < _loc3_.width)
  88.          {
  89.             _loc3_.setPixel(_loc1_,_loc2_,p_save[_loc2_][_loc1_]);
  90.             _loc1_ = _loc1_ + 1;
  91.          }
  92.          _loc2_ = _loc2_ + 1;
  93.       }
  94.       return _loc3_.clone();
  95.    }
  96.    function takePicture()
  97.    {
  98.       _root.blue._visible = false;
  99.       _root.hud._visible = false;
  100.       this._visible = false;
  101.       this.current_photo = new Photo();
  102.       this.current_photo_num = null;
  103.       _root.blue._visible = true;
  104.       _root.hud._visible = true;
  105.       this._visible = true;
  106.    }
  107.    function cameraPopup()
  108.    {
  109.       _root.hud.setText("");
  110.       this._parent.digi_cam.broadcastMessage("popup",null);
  111.       this.env.stopToPhoto();
  112.       this._x = 30;
  113.       this._y = 5;
  114.       this._alpha = 0;
  115.       this.touch_side._alpha = 0;
  116.       this.setFadeIn();
  117.    }
  118.    function cameraPopdown()
  119.    {
  120.       this._parent.digi_cam.broadcastMessage("popdown",null);
  121.       if(!this.env.inside)
  122.       {
  123.          this.env.stopPhotoing();
  124.       }
  125.       this._alpha = 100;
  126.       this.setFadeOut();
  127.    }
  128.    function viewCurrentPhoto()
  129.    {
  130.       this.emptyScreen();
  131.       this.screen.createEmptyMovieClip("holder_clip",1);
  132.       this.screen.holder_clip.attachBitmap(this.current_photo.image,1);
  133.    }
  134.    function viewAllPhotos()
  135.    {
  136.       this.emptyScreen();
  137.       var _loc4_ = 0;
  138.       while(_loc4_ < 3)
  139.       {
  140.          var _loc3_ = 0;
  141.          while(_loc3_ < 3)
  142.          {
  143.             var _loc2_ = 3 * _loc4_ + _loc3_;
  144.             this.screen.createEmptyMovieClip("holder_clip" + _loc2_,_loc2_ + 1);
  145.             this.screen["holder_clip" + _loc2_]._x = 80 * _loc3_;
  146.             this.screen["holder_clip" + _loc2_]._y = 50 * _loc4_;
  147.             this.screen["holder_clip" + _loc2_]._xscale = this.screen["holder_clip" + _loc2_]._yscale = 28;
  148.             this.screen["holder_clip" + _loc2_].photo = _loc2_;
  149.             this.screen["holder_clip" + _loc2_].attachBitmap(this.save.photos[_loc2_].image,_loc2_ + 1);
  150.             _loc3_ = _loc3_ + 1;
  151.          }
  152.          _loc4_ = _loc4_ + 1;
  153.       }
  154.    }
  155.    function emptyScreen()
  156.    {
  157.       for(var _loc2_ in this.screen)
  158.       {
  159.          this.screen[_loc2_].removeMovieClip();
  160.       }
  161.    }
  162.    function setForSelection()
  163.    {
  164.       var s = this.save.photos;
  165.       for(var _loc2_ in this.screen)
  166.       {
  167.          if(s[this.screen[_loc2_].photo].object_id != undefined)
  168.          {
  169.             this.screen[_loc2_].onRelease = function()
  170.             {
  171.                this._parent._parent.current_photo_num = this.photo;
  172.                this._parent._parent.current_photo = s[this.photo];
  173.                this._parent._parent.setTouchFadeIn(6);
  174.                this._parent._parent.viewCurrentPhoto();
  175.             };
  176.          }
  177.       }
  178.    }
  179.    function setForReplacement()
  180.    {
  181.       var s = this.save.photos;
  182.       for(var _loc2_ in this.screen)
  183.       {
  184.          if(s[this.screen[_loc2_].photo].object_id != undefined)
  185.          {
  186.             this.screen[_loc2_].onRelease = function()
  187.             {
  188.                this._parent._parent.replacement = this._parent._parent.current_photo;
  189.                this._parent._parent.current_photo_num = this.photo;
  190.                this._parent._parent.current_photo = s[this.photo];
  191.                this._parent._parent.setTouchFadeIn(4);
  192.                this._parent._parent.viewCurrentPhoto();
  193.             };
  194.          }
  195.       }
  196.    }
  197.    function replacePhoto()
  198.    {
  199.       this.save.photos[this.current_photo_num] = this.replacement;
  200.       this.cameraPopdown();
  201.    }
  202.    function deletePhoto()
  203.    {
  204.       var _loc2_ = this.current_photo_num;
  205.       while(_loc2_ < 8)
  206.       {
  207.          this.save.photos[_loc2_] = this.save.photos[_loc2_ + 1];
  208.          _loc2_ = _loc2_ + 1;
  209.       }
  210.       this.save.photos[8] = {object_id:undefined,image:new flash.display.BitmapData(225,140,false,0)};
  211.       this.viewSavedPhotos();
  212.    }
  213.    function takeNewPhoto()
  214.    {
  215.       this.emptyScreen();
  216.       this.takePicture();
  217.       this.viewCurrentPhoto();
  218.       this.setTouchFadeIn(1);
  219.    }
  220.    function viewSavedPhotos()
  221.    {
  222.       this.emptyScreen();
  223.       this.viewAllPhotos();
  224.       this.setTouchFadeIn(5);
  225.       this.setForSelection();
  226.    }
  227.    function saveCurrentPhoto()
  228.    {
  229.       var i = 0;
  230.       while(i < 9)
  231.       {
  232.          if(this.save.photos[i].object_id == undefined)
  233.          {
  234.             this.touch_side.gotoAndStop(2);
  235.             this.onEnterFrame = function()
  236.             {
  237.                this.save.photos[i] = this.current_photo;
  238.                this.cameraPopdown();
  239.             };
  240.             return undefined;
  241.          }
  242.          i++;
  243.       }
  244.       this.viewSavedPhotos();
  245.       this.setForReplacement();
  246.       this.setTouchFadeIn(3);
  247.    }
  248.    function setTouchFadeIn(p_frame)
  249.    {
  250.       this.touch_side.gotoAndStop(p_frame);
  251.       this.touch_side._alpha = 0;
  252.       this.touch_side.onEnterFrame = function()
  253.       {
  254.          if(this._parent._alpha > 99)
  255.          {
  256.             this._alpha += 30;
  257.             if(this._alpha > 99)
  258.             {
  259.                this.onEnterFrame = function()
  260.                {
  261.                };
  262.             }
  263.          }
  264.       };
  265.    }
  266.    function setFadeIn()
  267.    {
  268.       this.onEnterFrame = function()
  269.       {
  270.          this._alpha += 30;
  271.          if(this._alpha > 99)
  272.          {
  273.             this.onEnterFrame = function()
  274.             {
  275.             };
  276.          }
  277.       };
  278.    }
  279.    function setFadeOut()
  280.    {
  281.       this.onEnterFrame = function()
  282.       {
  283.          this._alpha -= 30;
  284.          if(this._alpha < 0)
  285.          {
  286.             this._x = 60;
  287.             this._y = 500;
  288.             this.onEnterFrame = function()
  289.             {
  290.             };
  291.          }
  292.       };
  293.    }
  294. }
  295.