2010年9月1日水曜日

[MA-6] Flash Lite向けストップウォッチ(Flash Lite)



ex6_stop_watch_lite2.swf

ActionScript2.0
startFlag = false;
nowTime = 0;
startTime = 0;
dispBaseTime = 0;
//
_root.onEnterFrame = function() {
 _root.numDisp(0, 0);
 _root.numDisp(0, 1);
 _root.numDisp(0, 2);
};
//
startButton.onRelease = function() {
 if (startFlag == false) {
  _root.startTime = getTimer() - _root.dispBaseTime;
  _root.onEnterFrame = displayUpdate;
  startFlag = true;
 } else {
  _root.onEnterFrame = null;
  startFlag = false;
 }
};
//
resetButton.onRelease = function() {
 _root.nowTime = 0;
 _root.startTime = 0;
 _root.dispBaseTime = 0;
 _root.startFlag = false;
 _root.onEnterFrame = null;
 _root.numDisp(0, 0);
 _root.numDisp(0, 1);
 _root.numDisp(0, 2);
};
//
function displayUpdate() {
 _root.nowTime = getTimer();
 _root.dispBaseTime = _root.nowTime - _root.startTime;
 milliSecond = Math.floor(dispBaseTime / 10);
 milliSecond = ("00" + milliSecond).substr(-2, 2);
 swSecond = Math.floor(dispBaseTime / 1000 % 60);
 if (swSecond < 10) {
  swSecond = "0" + swSecond;
 }
 minutae = Math.floor(dispBaseTime / 1000 / 60);
 if (minutae < 10) {
  minutae = "0" + minutae;
 }
 _root.numDisp(minutae, 0);
 _root.numDisp(swSecond, 1);
 _root.numDisp(milliSecond, 2);
}
//
var keta:Number = 2;
function numDisp(getNum:Number, output:Number):Void {
 var i:Number = 0;
 var maxNum:Number = Math.pow(10, keta) - 1;
 var num:Number = Math.max(Math.min(getNum, maxNum), 0);
 var strNum:String = "0000" + String(num);
 strNum = strNum.substr(strNum.length - keta, keta);
 for (i = 0; i < keta; i++) {
  switch (output) {
  case 0 :
   _root["numMcMinutae" + i].gotoAndStop(Number(strNum.charAt(i)) + 1);
   break;
  case 1 :
   _root["numMcSwSec" + i].gotoAndStop(Number(strNum.charAt(i)) + 1);
   break;
  case 2 :
   _root["numMcSwMiliSec" + i].gotoAndStop(Number(strNum.charAt(i)) + 1);
   break;
  }
 }
}
ダウンロード

0 件のコメント: