Dot Syntax

I l @ ve RuBoard

Something else that you will be seeing a lot of as you learn ActionScript is dot syntax. Dot syntax is a way of grouping objects and functions that is used in many object-oriented programming languages.

Here is an example of dot syntax. Suppose that you want to take the square root of a number. Flash has a built-in square root function. It is a part of a group of math functions called the math object. To use the square root function, you first have to use the name of the math object, which is simply Math . The name of the function is sqrt . So this is how you would use the math object's square root function:

 var a = Math.sqrt(4); 

We'll look at the math object and its functions, as well as other objects like it, throughout the book.

Another common way to use dot syntax is to address a property of a movie clip. Suppose that you have a move clip named myClip and you wanted to determine its horizontal position on the screen. That would be the _x property of the movie clip. So the code would look like this:

 var a = myClip._x; 

We'll look at all the different movie clip properties as we need to use them in future hours, particularly in Hour 7, "Moving and Changing Movie Clips."

You can also use dot syntax to reference global variables inside other movie clips. So if you have code in a movie clip and are using a global variable inside that movie clip, you can access it from the root level like this:

 var a = myClip.myVariable 

Don't worry if you aren't sure about objects, movie clip properties, or movie clip levels. We'll examine each of these more throughout the book as we use them, particularly in Hour 6, "Controlling Movie Clips," and Hour 7. Right now, it is just important that you understand what dot syntax looks like.

I l @ ve RuBoard

Sams Teach Yourself Flash MX ActionScript in 24 Hours
Sams Teach Yourself Flash MX ActionScript in 24 Hours
ISBN: 0672323850
EAN: 2147483647
Year: 2002
Pages: 272 © 2008-2017.
If you may any questions please contact us: