Graphics Programs Reference
In-Depth Information
Step 1: Getting started
Open 5_4_sineWave.fla in the Chapter 5 folder. Before we get to the script, it might
be helpful to take a quick look at some of the key elements. For the pendulum to rotate
properly, its registration point must be set to the top center of the object with the top
of the pendulum located at the center of the clock as shown in Figure 5.27. This was
easy to accomplish by placing the pendulum layer on top of the clock layer. Since we
want the pendulum to be visually behind the clock, a mask is needed to produce the
right effect. You can see the mask by unlocking its layer.
Figure 5.27 Positioning the pendulum and its mask
Step 2: Initialize pendulum variables
The first thing we need to do is to initialize some key pendulum variables that we will
be using. The amplitude is set to 30 in line 2. Recall that this will dictate how far the
pendulum will swing back and forth. The other variable we'll set is the frequency, which
is a measure of how many times the pendulum swings back and forth per minute. At
first the pendulum is not moving, so we set the frequency to 0. We will update this later
after the user clicks on the pendulum.
1
2
3
4
// initialize pendulum variables
A = 30; // A = amplitude (maximum amount of swing)
f = 0; // f = frequency
Step 3: Get at the actual time
It seems like a nice idea to have our clock show the actual time. Fortunately for us,
Flash enables us to do this quite easily. We'll define a function getTime() , which we
Search WWH ::




Custom Search