Change member variable value in member method : Method « Class « Flash / Flex / ActionScript






Change member variable value in member method

 
class Car {
          
          public var speed:Number;
          public var direction:String;
          
          public var onSpeedChange:Function;
          public var onDirectionChange:Function;

          public function Car(speed,direction) {
               this.speed = speed;
               this.direction = direction;
          }

          public function increaseSpeed() {
               this.speed += 10;
               this.onSpeedChange();
          }

          public function setDirection(direction) {
               this.direction = direction;
               this.onDirectionChange();
          }
          
     }

        








Related examples in the same category

1.Defining Methods for a Class
2.Adding Static Methods to a Class
3.Create a method and then call it by name
4.A simple example of a method declaration using parameters