Object-Oriented Programming with ActionScript 2.0
< Day Day Up > |
In Chapter 2, "All the World Is an Object," the text looked at a class called Loan . The Loan class had several properties that described aspects of a loan, such as principal , rate , and term . These properties acted much like a variable within the loan instances. In reality, that's exactly what a property is: a variable belonging to an object. Properties can be used in exactly the same ways as a variable. That is, they can be passed to functions, compared with conditionals, and so on. In reality, what we know of as a variable is actually a property; the movie clip or timeline on which it is coded is the object to which it belongs. Consider this example: In Frame 1 of the Actions layer on the main timeline, this code is entered: var myName:String = "jeff";
This can be demonstrated by tracing it in several different ways: trace(myName); trace(this.myName); trace(_root.myName); Each elicits exactly the same response. What this shows is that a simple variable within a movie clip can be referred to as a variable (shown with the first trace statement) or as a property of an object (shown in the second and third trace statements). To refer to the variable as a property, it needs to be referenced using the object.property notation. It is a property of a movie clip on whose timeline it is coded, which we can refer to by its relative address this or its absolute address _root . |
< Day Day Up > |