The Dot Operator


You might have noticed in the previous example that when we were scripting in the main timeline and we wanted to access a variable that was declared within a script attached to a movie clip that existed on the main timeline, we used the name of the movie clip instance followed by a period or dot followed by the variable name . This is called dot notation . In other words, I'm talking about this code:

 ball2.myString 

Dot notation is the way we indicate a possession of, or a component of, something. For example, if you wanted to discuss your stove when you were at the beach , you might say something like, "My kitchen stove is broken." In ActionScript, you would say this:

 myHouse.kitchen.stove; 

We'll be using dot notation all over the place in our games because we'll want variables that pertain to a certain movie clip to be declared inside that movie clip. That way, several movie clips of the same kind can have different variables with the same name. If we want to have 100 alien invaders each with their own hit points, damage, and speed variables , we can do that. Then when the player shoots one, we might have a piece of script like the following:

 alien103.hitPoints -= 10; 

As you can see, there isn't really much to the dot operator. It's used to access variables inside a clip or object, and it's also used to access functions inside them. For example:

 alien103.moveDown(); 

This script assumes that there is a function defined on the alien103 clip called moveDown that does some work. Because it's attached to the alien103 clip, it can be accessed with the dot operator like that.




Macromedia Flash MX 2004 Game Programming
Macromedia Flash MX 2004 Game Programming (Premier Press Game Development)
ISBN: 1592000363
EAN: 2147483647
Year: 2004
Pages: 161

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net