|< Day Day Up >|
Just as all real-world objects can be described by their properties, the same holds true for internal Flash objects. Figure 3.1 shows the properties for a movie clip.
Figure 3.1. The properties of a movie clip.
Some of these properties are familiar, indicating positioning on the Stage ( _x , _y ), size (_height , _width , _xscale , and _yscale ), and information about frames (_ totalFrames , _ framesLoaded , and _ currentFrame ). Each property describes the unique characteristics of an instance of a movie clip.
We can also find similar information about the properties of any of the built-in objects in Flash. For example, an instance of the Array class has a property describing the number of elements within the array ( length ), a TextField instance has a property that describes the text currently within it ( text ), and an instance of the Sound class has a property to describe how long the sound lasts ( duration ).
Working with properties of an object is as simple as working with variables on the main timeline. Figure 3.2 shows a simple use of the properties of TextField instances to facilitate simple addition.
Figure 3.2. Using the text property of TextField instances enables you to read and write to them.
On the Stage are three text fields and a button. The top two text fields ( input1 and input2 ) are input text; the bottom is a dynamic text field ( total ). An onRelease event is added for the button instance ( btAdd ). When clicked and released, the text properties of the two input fields are added, and the results are shown in the total field. We can see that to read a user 's input from a text field, we refer to the text property of that field. In addition, to assign text to a text field, we also use the same text property.
Note that this simple example of the use of properties within Flash is flawed. Figure 3.3 shows what happens if we run the file and attempt to use it to add 2 and 3.
Figure 3.3. The Addition tool shows some unexpected results.
|< Day Day Up >|