Static Variables: define methods and properties that belong to the class itself, rather than their instances. : static « Class « Flash / Flex / ActionScript






Static Variables: define methods and properties that belong to the class itself, rather than their instances.

 


package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var fixedGear:Bicycle = new Bicycle(1);
       // trace(fixedGear.wheels); //Wrong! Compiler error.
        trace(Bicycle.wheels); //Right! 2


    }
  }
}
class Bicycle
    {
        public static var wheels:Number = 2;

        private var _gears:Number;
        public function get gears():Number
        {
            return _gears;
        }

        public function Bicycle(numberOfGears:Number)
        {
            this._gears = numberOfGears;
        }
    }

        








Related examples in the same category

1.Static Variables
2.Static Methods
3.Using Static Methods and Properties
4.Reference static variable
5.Static Constants