Flash / Flex / ActionScript/Language/const

Материал из Web эксперт
Перейти к: навигация, поиск

A constant is a variable which remains fixed for the remainder of the program.

 
public class MyState {
  public static const MODE_VISUAL = 1;
  public static const MODE_AUDIO  = 2;
  public static const MODE_BOTH   = 3;
  private var mode = MyState.MODE_AUDIO;
  private function signalAlarm (  ) {
    if (mode == MODE_VISUAL) {
    } else if (mode == MODE_AUDIO) {
    } else if (mode == MODE_BOTH) {
    }
  }
}



Define and use Constants

 
package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        const BOILING_POINT:int = 212;
        
        trace(BOILING_POINT);
    }
  }
}