Hi,
i have created a Vehicle.as file and a Car.as file which are in the same project. The problem i am having is trying to use the properties in my Car.as from my Vehicle.as file.
Vehicle.as
package
{
/**
* Vehicle.as is meant to show a vehicle class
* @author Luong Vuong
* Date created: 29/09/2009
* Last modified: 11/10/2009
*/
import flash.display.MovieClip;
import flash.events.Event;
public class Vehicle extends MovieClip
{
private var _gasMileage:Number;
private var _fuelAvailable:Number;
private var _milesTraveled:Number = 0;
private var _go:Boolean;
public function Vehicle(mpg:Number = 21, fuel:Number = 18) :void
{
_gasMileage = mpg;
_fuelAvailable = fuel;
this.addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);
construct();
}
// If true, decrease the fule and increase the miles traveld
// If the fuel is less than 1 remove the listener from the object
// Trace the resulting object and milestraveld and fuel available for every iteration
// Set the x location for the object
public function onLoop(evt:Event) :void
{
if (_go)
{
_fuelAvailable--;
_milesTraveled += _gasMileage;
if ( _fuelAvailable < 1 )
{
this.removeEventListener(Event.ENTER_FRAME, onLoop);
}
trace(this, _milesTraveled, _fuelAvailable);
this.x = _milesTraveled;
}
}
// Start engine and drive
public function go() :void
{
_go = true;
}
}
}
Car.as
package
{
/**
* Car.as is meant to show how you can inherit from another class, Vehicle and add another property and method
* @author Luong Vuong
* Date created: 13/10/2009
* Last modified: 13/10/2009
*/
import flash.display.Sprite;
import flash.events.Event;
public class Car extends Vehicle
{
public function Car(mpg:Number, fuel:Number) :void
{
_gasMileage = mpg;
}
// Class methods
}
}
When i type this line of code, _gasMileage = mpg; and build it i get the following error,
C:\Users\vista\Documents\FlashDevelopProjects\VehicleApp\Car.as(20): col: 4 Error: Attempted access of inaccessible property _gasMileage through a reference with static type Car.
Now i tried to add an import statement i.e import Vehicle but that did not work. How can i use the private attributes of my Vehicle class in my Car class appropriately?
P.S I AM USING FLASHDEVELOP, NOT FLASH IDE TO DO THIS