home *** CD-ROM | disk | FTP | other *** search
/ FCE Gold Plus / GOLD.iso / pc / shell.swf / scripts / __Packages / com / comp / Timer.as < prev    next >
Text File  |  2007-10-16  |  5KB  |  173 lines

  1. class com.comp.Timer
  2. {
  3.    var c_boolVar = true;
  4.    function Timer(_objRoot, _iTotTime, _iTotSecTime, _strSourceClip, _strMinField, _objTestRef)
  5.    {
  6.       var _loc1_ = this;
  7.       _loc1_.c_objRef = _objRoot;
  8.       _loc1_.c_mcSourceRef = _objRoot[_strSourceClip];
  9.       _loc1_.c_txtMinRef = _loc1_.c_mcSourceRef[_strMinField];
  10.       _loc1_.c_iTotalTime = _iTotTime;
  11.       _loc1_.c_objTestRef = _objTestRef;
  12.       _loc1_.init(_iTotTime,_iTotSecTime);
  13.    }
  14.    function init(_iMinutes, _iSeconds)
  15.    {
  16.       var _loc1_ = this;
  17.       _loc1_.c_iMins = Number(_iMinutes);
  18.       _loc1_.c_iTimerDuration = Number(_iMinutes);
  19.       _loc1_.c_iSecs = Number(_iSeconds);
  20.       _loc1_.c_iMins = _loc1_.c_iMins - 1;
  21.       _loc1_.changedTime();
  22.       _loc1_.c_txtMinRef.htmlText = "<b>" + _loc1_.c_iChangedMins + "</b>" + " mins";
  23.       if(_loc1_.c_iMins < 10)
  24.       {
  25.          _loc1_.c_iMins = "0" + _loc1_.c_iMins;
  26.       }
  27.       _loc1_.arrange();
  28.    }
  29.    function arrange()
  30.    {
  31.       this.startTimer();
  32.    }
  33.    function startTimer()
  34.    {
  35.       var _loc1_ = this;
  36.       _loc1_.c_objInterval = setInterval(_loc1_.showTimer,1000,_loc1_);
  37.    }
  38.    function stopTimer()
  39.    {
  40.       clearInterval(this.c_objInterval);
  41.    }
  42.    function showTimer(_objRef)
  43.    {
  44.       with(_objRef)
  45.       {
  46.          if(c_iSecs <= 0)
  47.          {
  48.             c_iSecs = 60;
  49.             actualTime();
  50.          }
  51.          c_iSecs--;
  52.          if(c_iSecs < 10)
  53.          {
  54.             c_iSecs = "0" + c_iSecs;
  55.          }
  56.          if(c_iMins == 15 || c_iMins == 5)
  57.          {
  58.             if(c_iMins == 5)
  59.             {
  60.                c_blnPopUp = false;
  61.             }
  62.             if(!c_blnPopUp && c_iSecs == 0)
  63.             {
  64.                _objRef = _level101.mc_PopUp;
  65.                _objRef.gotoAndStop("timeleft");
  66.                c_blnPopUp = true;
  67.                _objRef._x = 232.9;
  68.                _objRef._y = 181.4;
  69.                _objRef.txt_TimeLeft.text = Number(c_iMins) + " mins remaining";
  70.                _objRef.btn_backtotest.onRelease = function()
  71.                {
  72.                   _objRef.gotoAndStop("blank");
  73.                };
  74.             }
  75.          }
  76.          if(c_iSecs <= 0 && c_iMins <= 0)
  77.          {
  78.             gameOver();
  79.             stopTimer();
  80.          }
  81.       }
  82.       _objRef.setEvents(_objRef);
  83.       _objRef.setTimer();
  84.       _objRef.getminsTime();
  85.    }
  86.    function setEvents(_objRef)
  87.    {
  88.       this.c_mcSourceRef.onRollOver = function()
  89.       {
  90.          _objRef.c_boolVar = false;
  91.          _objRef.setTimer();
  92.       };
  93.       this.c_mcSourceRef.onRollOut = function()
  94.       {
  95.          _objRef.c_boolVar = true;
  96.          _objRef.setTimer();
  97.       };
  98.    }
  99.    function setTimer()
  100.    {
  101.       var _loc1_ = this;
  102.       if(_loc1_.c_iMins <= 10)
  103.       {
  104.          _loc1_.c_txtMinRef.textColor = 65295;
  105.       }
  106.       if(_loc1_.c_boolVar)
  107.       {
  108.          _loc1_.c_txtMinRef.htmlText = "<p><b>" + _loc1_.c_iChangedMins + "</b>" + " mins" + "</p>";
  109.       }
  110.       else
  111.       {
  112.          _loc1_.c_txtMinRef.htmlText = "<p align=\'center\'><b>" + _loc1_.c_iMins + ":" + _loc1_.c_iSecs + "</b></p>";
  113.       }
  114.    }
  115.    function actualTime()
  116.    {
  117.       var _loc1_ = this;
  118.       _loc1_.c_iMins = _loc1_.c_iMins - 1;
  119.       if(_loc1_.c_iMins < 10)
  120.       {
  121.          _loc1_.c_iMins = "0" + _loc1_.c_iMins;
  122.       }
  123.       _loc1_.changedTime();
  124.       return _loc1_.c_iMins;
  125.    }
  126.    function changedTime()
  127.    {
  128.       var _loc2_ = this;
  129.       var _loc1_ = Number(_loc2_.c_iMins) + Number(1);
  130.       if(_loc1_ < 10)
  131.       {
  132.          _loc2_.c_iChangedMins = "0" + _loc1_;
  133.       }
  134.       else
  135.       {
  136.          _loc2_.c_iChangedMins = _loc1_;
  137.       }
  138.       return _loc2_.c_iChangedMins;
  139.    }
  140.    function gameOver()
  141.    {
  142.       trace("Game Over");
  143.       clearInterval(this.c_objInterval);
  144.       this.c_objTestRef.popupNo();
  145.    }
  146.    function alerts()
  147.    {
  148.       trace("YOU HAVE ONLY 15 MINS");
  149.    }
  150.    function resetTimer()
  151.    {
  152.       this.init(this.c_iTimerDuration);
  153.    }
  154.    function destroyTimer()
  155.    {
  156.       clearInterval(this.c_objInterval);
  157.       this.c_mcSourceRef.removeMovieClip();
  158.    }
  159.    function getMinsTime()
  160.    {
  161.       var _loc1_ = undefined;
  162.       _loc1_ = Number(this.c_iTotalTime) - Math.floor(Number(this.c_iMins));
  163.       return _loc1_;
  164.    }
  165.    function getSecTime()
  166.    {
  167.       var _loc1_ = this;
  168.       var _min = Math.floor(_loc1_.c_iMins / 60);
  169.       var _sec = _loc1_.c_iMins % 60;
  170.       return _loc1_.c_iMins + "." + _loc1_.c_iSecs;
  171.    }
  172. }
  173.