Graphics Programs Reference
In-Depth Information
Step 5: Define the button actions
Select the arrow on the left and give it an instance name of ccw_btn in the Properties
window. We'll use this for counterclockwise rotation of the object. Similarly, give the
arrow on the right an instance name of cw_btn for clockwise rotation. Now let's define
the desired actions when the user clicks the buttons.
Referring to the script below, when the user presses down on the clockwise arrow, the
onPress handler sets the variable move to 1 and then sets it to 0 when the user releas-
es the button. We are going to use this variable to move the playback head one frame
forward in the objectMC Timeline. When the user releases the button, the playback
head will stop.
When the user presses down on the counterclockwise arrow, the onPress handler sets
the variable move to -1 and then sets it to 0 when the user releases the button. We
will use this to move the playback head one frame backward in the objectMC Timeline.
When the user releases the button, the playback head will stop as before.
6
7
8
9
10
11
12
13
14
15
// cw arrow - set up for clockwise move
cw_btn.onPress = function() { move = 1; }
cw_btn.onRelease = function() { move = 0; }
cw_btn.onReleaseOutside = function() { move = 0; }
// ccw arrow - set up for counterclockwise move
ccw_btn.onPress = function() { move = -1; }
ccw_btn.onRelease = function() { move = 0; }
ccw_btn.onReleaseOutside = function() { move = 0; }
Step 6: Rotate the object
We are now ready to set up the script to rotate the object. As usual, we will use an
onEnterFrame handler so that we can update the object continuously.
The first thing we are doing is setting the variable thisFrame to be the current frame
of the object movie clip. Next, thisFrame is updated by whatever the current value of
move has been set to. We must check whether the update has caused thisFrame to
go beyond the frame numbers of the movie clip. If thisFrame is greater than total-
Frames , the number of frames in the clip, we want to cycle back to the first frame for
continuous clockwise motion. Note that to have smooth motion, the first frame and
last frame should not be the same image.
Search WWH ::




Custom Search