2016-05-18 4 views
0

私はタイマーカウントダウンをしようとしていますが、私はそこにすべてのピースを持っていると信じています。 。フラッシュ - エラー:1013:プライベート属性がクラスプロパティ定義でのみ使用される可能性があります

何が起こっているのでしょうか?

package 

{ 
    import flash.display.MovieClip; 
    import flash.events.TimerEvent; 
    import flash.utils.Timer; 

    public class MainTimer extends MovieClip { 
     private var currentMin:int; 
     private var currentSec:int; 

     private var oneSecondTimer:Timer = new Timer (1000,1); 
     public var timeHasStopped:Boolean=false; 

     public function MainTimer() { 
     // constructor code 
      trace("the main timer is here"); 
      currentMin = 2; 
      currentSec = 5; 

      minBox.text = String(currentMin); 

      if(currentSec < 10) 
      { 
       secBox.text = "0" + String(currentSec); 
      } 
      else { 
       secBox.text = String(currentSec); 
      } 

      oneSecondTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete); 
      oneSecondTimer.start(); 

      private function onTimerComplete(event:TimerEvent):void { 
       currentSec = currentSec -1; 
       if(currentSec <0) 
        { 
         currentSec =59; 
         currentMin -=1; 
        } //end if 
       if(currentMin < 0) { 
         currentMin =0; 
         currentSec =0; 
         timerHasStopped = true; 
       } 
       else 
        { 
         oneSecondTimer.start(); 
        } 
       minBox.text =String(currentMin); 
       secBox.text =String(currentSec); 

       if(currentSec <10) 
        { 
         secBox.text = "0" + String(currentSec); 
        } 
      } 
    } // Ends Function 

} // Ends Class 

} // Ends Package 

答えて

1

functonは、開口部{括弧を持っている必要がありますし、あなたは別の新しい関数を作る前}で閉じる必要があります。あなたの} // Ends FunctionがラインoneSecondTimer.start();後に配置する必要がありますし、そこからすると、以降、あなたはあなたに他の第2の機能を定義することができますfunction onTimerComplete

それが役立つかもしれない

場合インデントあなたが簡単に確認物事が&終わりを始める場所(TABキーを使用する)ことができるようにあなたのコード。

インデントされたコードの例は、以下のようになります(テキストが削除されます)。この構造によってどのように中括弧を見やすくするかをご覧ください。&したがって、

public function MainTimer() 
{ 
    // constructor code 

    ....... 

    if(currentSec < 10) 
    { 
     ....... 
    } 
    else 
    { 
     ....... 
    } 

    ....... 

} //Ends function called MainTimer 

private function onTimerComplete(event:TimerEvent):void 
{ 
    ....... 

    if(currentSec <0) 
    { 
     ....... 
    } //end if 
    if(currentMin < 0) 
    { 
     ....... 
    } 
    else 
    { 
     ....... 
    } 

    ....... 

    if(currentSec <10) 
    { 
     ....... 
    } 
} //Ends function called onTimerComplete 
1

onTimerCompleteは、関数の中にあります。クラスメンバーではないため、privateキーワードは適用されません。

関連する問題