Ok, so I have found a tutorial which shows me how to create a class. It also shows me how to construct an object in the main code. What I want to do is to access a variable from the object that I made. Heres the code…
This is the link to the tutorial:
http://flash.lillegutt.com/?p=29
the Car.as file:
package
{
public class Car
{
// defining attributes to the car
private var _name:String = "My custom Porche";
private var _engine:Number = 6.3;
private var _numberWheels:int = 4;
private var _doors:String = "Elevating doors";
// The Car constructor
public function Car(name:String="custom car", engine:Number=0, numberWheels:int=4, doors:String="")
{
// setting the global attributes to the incoming variables
_name = name;
_engine = engine;
_numberWheels = numberWheels;
_doors = doors;
}
}
}
Then I use this code to construct the object, which in this case is a car (the code is in my main flash file):
var mycar:Car = new Car("Porche", 3.2, 4, "Normal doors");
I understand all of the code, but how do I reference a variable like the engine? I have tried lots of things like “trace(this[mycar].engine)”, "trace(mycar.engine) but nothing seems so work. I just get error messages of property undefined.
Any help would be really appreciated, thanks.