• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 5. Programming Structures > Simple Objects in Statements

Simple Objects in Statements

It’s only fair to introduce you to objects now. Even though there are seven other chapters dedicated to the finer points of objects (Chapter 7, “The Movie Clip Object;” Chapter 9, “Manipulating Strings;” Chapter 10, “Keyboard Access and Modifying Onscreen Text;” Chapter 11, “Arrays;” Chapter 12, “Objects;” Chapter 13, “Homemade Objects;” and Chapter 14, “Extending ActionScript”), there are a couple of simple objects that will help you immensely as you write statements—namely, the Math object and the Number object. Instead of providing detailed information about objects here, I’ll simply show you how to use the Math and Number objects. They’re so easy that you really can use them without fully understanding objects. When you get to the workshop chapters, you’ll find the Math Object useful in almost every exercise. You’ll use it in Workshop Chapter 3, “Creating a Horizontal Slider,” (to help determine the percentages) and in Workshop Chapter 11, “Using Math to Create a Circular Slider,” (to help determine the angles). In fact, you’ll find the Math Object invaluable if you ever want to go beyond simple addition, subtraction, multiplication, and division.

Using the Math Object

The Math object will give you access to both common mathematical functions as well as a few constants (such as pi). The functions in the Math object (called methods) are almost like the buttons on a scientific calculator; actually, they’re practically identical. For example, my calculator has a square root button (that looks like this: √). If I first type a 9 and then press the square root button, my calculator “returns” (into the display field) the square root of 9—that is, 3. Within an expression in Flash, you can also type a 9 (or a variable whose value happens to equal 9) and use the Math object’s square root method to return the square root into the expression where you used it. The expression looks like this: Math.sqrt(9). (Remember that as an expression, this evaluates to 3, but it doesn’t do anything unless you use it in a statement, such as answer=Math.sqrt(9);.)


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint