Flash ActionScript 2.0 – Class Inheritance

Every Flash Actiosnscript class has attributes and behaviours. Attributes can describe the state or qualities of an object:
Say we have a Car class. It might have the attributes of :
Color: red, green, blue.
Style – sedan, station wagon, urban assault vehicle.
Make – Toyota, Holden, Ford , Daihatsu
Attributes can also have information about its state.
has4WheelDrive – true , false;
currentGear – 1,2,3,4,R;
Let’s define a Car class(save it as Car.as) with what we have so far:

class Car{
	// declare attributes
	private var carColor:String;
	private var make:String;
	private var year:Number;
	private var style:String;
}

Methods

Methods define the behaviours of our classes. What do we want our car to do? how about move.. and stop. Lets add them..

class Car{
	// declare attributes
	private var xpos:Number;
	private var ypos:NUmber;
	private var speed:Number;
	private var carColor:String;
	private var make:String;
	private var year:Number;
	private var style:String;
	// Methods
	public function move(){
		xpos +=speed;
	}
	public function stop(){
		speed = 0;
	}
	
}

Leave a Reply

Your email address will not be published. Required fields are marked *