public class Vehicle extends MovieClip
{
public var _gasMileage:Number;
public var _fuelAvailable:Number;
public var _milesTraveled:Number = 0;
public var _go:Boolean;
//public var vehicle:Vehicle = new Vehicle(21, 18);
public function construct() :void
{
//addChild(vehicle);
//vehicle.go();
}
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;
}
}
}
VehicleOnly.as
Code:
package
{
/**
* VehicleOnly.as is meant to show
* @author Luong Vuong
* Date created: 30/09/2009
* Last modified: 30/09/2009
*/
import flash.display.Sprite;
import flash.events.Event;
public class VehicleOnly extends Sprite
{
public var vehicle:Vehicle = new Vehicle(21, 18);
public function VehicleOnly() :void
{
initialize();
construct();
}
// Initialize all variables
public function initialize() :void
{
addChild(vehicle);
}
// Add listeners and add UI to display list
public function construct() :void
{
vehicle.go();
}
// Class methods
}
}
When i create an instance of the Vehicle class in my VehicleOnly.as file and send the values to my constructor, and run the appplication, it does not show any output to my Output panel. I should be getting the following:
i kind of new that it would work on Adobe IDE but, i'm sadly not using it to build my class, like i said i'm using FlashDevelop. can you try to do this on FlashDevelop because i'm still not getting any output,.
AAH LIGHT BULB!!!!! I found out what the problem was. It struck me as i was sleeping, seriusly, after tackling it for 2 hours getting slightly frustrated. The problem was not the actual code in my VehicleOnly.as file. It was that on FlashDevelop every time you create a new .as file you need to set it to "Always Compile".
It was compiling my Vehicle.as file and not my VehicleOnly.as file, hope that makes sense.
Sorry if i have caused any inconvenience by the way.