Table of Contents
### Calculating Distances with the Math Class

Entire Site

Using the Pythagorean theorem, Flash makes it possible for you to calculate the distance between two objects. This technique can be useful for creating novel interactions among interface elements—graphics, buttons, or sounds whose reactions depend on their distance from the viewer’s pointer, for example. You can also create games that have interaction based on the distance between objects and the player. A game in which the player uses a net to catch goldfish in an aquarium, for example, can use the distance between the goldfish and the net to model the behavior of the goldfish. Perhaps the closer the net comes to a goldfish, the quicker the goldfish swims away.

The distance between any two points is defined by the equation