home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Aventura / Never_End.swf / scripts / game / FielsField.as < prev    next >
Encoding:
Text File  |  2008-09-23  |  5.3 KB  |  207 lines

  1. package game
  2. {
  3.    import flash.display.MovieClip;
  4.    import flash.events.MouseEvent;
  5.    import flash.geom.Rectangle;
  6.    import flash.text.TextField;
  7.    
  8.    [Embed(source="/_assets/assets.swf", symbol="game.FielsField")]
  9.    public class FielsField extends MovieClip
  10.    {
  11.        
  12.       
  13.       public var f10:MovieClip;
  14.       
  15.       public var f11:MovieClip;
  16.       
  17.       public var f13:MovieClip;
  18.       
  19.       public var f14:MovieClip;
  20.       
  21.       private var scrollBar:Button;
  22.       
  23.       public var f12:MovieClip;
  24.       
  25.       public var BG:MovieClip;
  26.       
  27.       public var sc:scrollbar;
  28.       
  29.       public var txt:TextField;
  30.       
  31.       public var files:Array;
  32.       
  33.       public var currentOpened:MovieClip;
  34.       
  35.       public var f6:MovieClip;
  36.       
  37.       public var f7:MovieClip;
  38.       
  39.       public var f4:MovieClip;
  40.       
  41.       public var f8:MovieClip;
  42.       
  43.       public var f1:MovieClip;
  44.       
  45.       public var f3:MovieClip;
  46.       
  47.       public var f5:MovieClip;
  48.       
  49.       public var f9:MovieClip;
  50.       
  51.       private var txtHeight:Number = 0;
  52.       
  53.       public var f2:MovieClip;
  54.       
  55.       public var _txt:TextField;
  56.       
  57.       public function FielsField()
  58.       {
  59.          txtHeight = 0;
  60.          super();
  61.          _txt = getChildByName("txt") as TextField;
  62.          scrollBar = getChildByName("sc") as Button;
  63.          scrollBar.addEventListener(MouseEvent.MOUSE_DOWN,dragBar,false,0,true);
  64.          initFiles();
  65.       }
  66.       
  67.       private function showFile(param1:MouseEvent) : void
  68.       {
  69.          var _loc2_:MovieClip = null;
  70.          var _loc3_:uint = 0;
  71.          var _loc4_:* = undefined;
  72.          _loc2_ = param1.currentTarget as MovieClip;
  73.          if(_loc2_.name != currentOpened.name)
  74.          {
  75.             currentOpened.gotoAndStop("full");
  76.             currentOpened = param1.currentTarget as MovieClip;
  77.             _loc3_ = Number(currentOpened.name.split("f")[1]);
  78.             currentOpened.gotoAndStop("open");
  79.             for each(_loc4_ in files)
  80.             {
  81.                if(Number(_loc4_) == _loc3_)
  82.                {
  83.                   _txt.text = Model.getInstance().getMessage(_loc3_);
  84.                   resetScrollBar();
  85.                }
  86.             }
  87.          }
  88.       }
  89.       
  90.       private function dragBar(param1:MouseEvent) : void
  91.       {
  92.          scrollBar.startDrag(false,new Rectangle(623.5,208,0,105.5));
  93.       }
  94.       
  95.       public function saveBook() : void
  96.       {
  97.          var _loc1_:Array = null;
  98.          var _loc2_:* = undefined;
  99.          _loc1_ = new Array();
  100.          for each(_loc2_ in files)
  101.          {
  102.             _loc1_.push(_loc2_);
  103.          }
  104.          Model.getInstance().currentData.ateBooks = _loc1_;
  105.       }
  106.       
  107.       public function addNewFile(param1:*, param2:Boolean = false) : void
  108.       {
  109.          var _loc3_:MovieClip = null;
  110.          files.push(param1.data);
  111.          if(currentOpened != null)
  112.          {
  113.             currentOpened.gotoAndStop("full");
  114.          }
  115.          _loc3_ = this.getChildByName("f" + param1.data) as MovieClip;
  116.          _loc3_.gotoAndStop("open");
  117.          currentOpened = _loc3_;
  118.          _txt.text = Model.getInstance().getMessage(int(param1.data));
  119.          resetScrollBar();
  120.          _loc3_.addEventListener(MouseEvent.CLICK,showFile,false,0,true);
  121.       }
  122.       
  123.       private function initFiles() : void
  124.       {
  125.          var _loc1_:Array = null;
  126.          var _loc2_:Array = null;
  127.          var _loc3_:* = undefined;
  128.          currentOpened = null;
  129.          files = new Array();
  130.          _loc1_ = Model.getInstance().currentData.ateBooks;
  131.          if(Model.cData == null)
  132.          {
  133.             _loc2_ = new Array();
  134.          }
  135.          else
  136.          {
  137.             _loc2_ = Model.cData.ateBooks;
  138.          }
  139.          if(_loc1_ == null)
  140.          {
  141.             if(_loc2_ != null)
  142.             {
  143.                _loc1_ = _loc2_;
  144.             }
  145.             else
  146.             {
  147.                _loc1_ = new Array();
  148.             }
  149.          }
  150.          else if(_loc2_ != null && _loc2_.length > _loc1_.length)
  151.          {
  152.             _loc1_ = _loc2_;
  153.          }
  154.          Model.books = files;
  155.          for each(_loc3_ in _loc1_)
  156.          {
  157.             addNewFile({"data":_loc3_},true);
  158.          }
  159.       }
  160.       
  161.       public function reset() : void
  162.       {
  163.          var i:int = 0;
  164.          var cld:MovieClip = null;
  165.          _txt.text = "";
  166.          resetScrollBar();
  167.          i = 1;
  168.          while(i <= 14)
  169.          {
  170.             cld = this.getChildByName("f" + i) as MovieClip;
  171.             cld.gotoAndStop("empty");
  172.             try
  173.             {
  174.                cld.removeEventListener(MouseEvent.CLICK,showFile);
  175.             }
  176.             catch(e:Error)
  177.             {
  178.             }
  179.             i++;
  180.          }
  181.          initFiles();
  182.       }
  183.       
  184.       private function resetScrollBar() : void
  185.       {
  186.          _txt.y = 201;
  187.          txtHeight = _txt.textHeight + 25;
  188.          scrollBar.x = 623.5;
  189.          scrollBar.y = 208;
  190.       }
  191.       
  192.       public function setTxt() : void
  193.       {
  194.          if(txtHeight < 115)
  195.          {
  196.             return;
  197.          }
  198.          _txt.y = 201 - (txtHeight - 115) / 115 * (scrollBar.y - 208);
  199.       }
  200.       
  201.       public function _stopDrag() : void
  202.       {
  203.          scrollBar.stopDrag();
  204.       }
  205.    }
  206. }
  207.