がるの健忘録

エンジニアでゲーマーで講師で占い師なおいちゃんのブログです。

タイマー的なバー

ほぼmemo。
パッケージみたいなのに出来るんじゃないかと思うんだけど、未確認。

めいん関数 {
  // max時間の設定
  this.time_count_ = 20;
  h1.maximum = this.time_count_;
  h1.value =   this.time_count_;
  h1.minimum = 0;

  // タイマーの設定
  var timer:Timer = new Timer(1000, this.time_count_ );
  timer.addEventListener(TimerEvent.TIMER, dec_timer);
  timer.start();
}

//  減算とタイムアウトの設定
private function dec_timer(ev:TimerEvent)
{
  h1.value = -- this.time_count_;
  if ( 0 == this.time_count_) {
    // タイムアウト!!
    Alert.show("fin!!");
  }
}

//
private var time_count_:int;


そいえば。callbackのところに直接関数書いて、いわゆる「無記名関数」的なことは、可能みたい。

      timer.addEventListener(TimerEvent.TIMER, function(ev:TimerEvent):void {
        text.text = String(i++);
      });


いぢょ ノ