Custom Objects
From Orielly
----------------------------
….Central to this behavior is the ability for an object to have properties (which are essentially descriptive elements that contribute to the object’s general characteristics, like width, location, rotation, and so on), methods (which are actions the object can perform), and even events (custom events that, like a mouse click or a key press, can trigger other processes in the course of working with a script).
----------------------------
From Orielly
----------------------------
You can also create custom objects and define your own properties, methods, and events.
----------------------------
From Orielly
---------------------------
var plane:Object = new Object();
plane.pitch = 0;
plane.roll = 5;
plane.yaw = 5;
trace(plane.pitch);
//0
-------------------------------
The people who created Actionscript could easily have created some other thing like a super variable, where an ‘obj’ is a varibale that is an object. It may have looked like this:
obj plane():void;
//not real code
plane.pitch = 0;
plane.roll = 5;
plane.yaw = 5;
Instead, they simply made an object a type of role a variable could play.
(I will say that you can do this too, but that is another thing in itself, it is what that “package” stuff is all about )
From Orielly
--------------------------------
function showPlaneStatus(obj:Object):void
{
trace(obj.pitch);
trace(obj.roll);
trace(obj.yaw);
};
showPlaneStatus(plane);
//0
//5
//5
-----------------------------------
So, we switch out “obj” which is an object, for “plane”. Then we trace the “showPlaneStatus” function with plane playing the object role. Remember we made “plane” an object:
var plane:Object = new Object();
plane.pitch = 0;
plane.roll = 5;
plane.yaw = 5;
I wouldn’t have called the function “showPlaneStatus”, since I could not only show the plane’s status, but the status of any object I put in the parenthesis. My script could look like this:
var plane: Object = new Object ();
plane.pitch = 0;
plane.roll = 5;
plane.yaw = 5;
var jet: Object = new Object();
jet.pitch = .3;
jet.roll = 2;
jet.yaw =2;
function showStatus(obj:Object):void
{
trace(obj.pitch);
trace(obj.roll);
trace(obj.yaw);
};
showStatus(plane);
showStatus(jet);
//0
//5
//5
//.3
//2
//2
And if I want to show the status of any other object I would just pass it to the “showStatus” function.
Notice that we have defined our own properties. there are built in properties in Actionscript that change objects accordingly. Here are some:
x
y
scaleX
scaleY
width
height
rotation
alpha
visible
mouseX
mouseY
Right now, our custom properties do nothing but show numbers.
From Orielly
---------------------------------
------------------------------------