Graphics Programs Reference
In-Depth Information
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// rotate the object
object_mc.onEnterFrame = function()
{
// get the current frame
var thisFrame:Number = object_mc._currentframe;
// update to the next frame
thisFrame += move;
// test the ends of the movie clip
if (thisFrame > totalFrames) { thisFrame = 1; }
if (thisFrame < 1) { thisFrame = totalFrames; }
// display the object
object_mc.gotoAndStop(thisFrame);
}
Similarly, if the update produces a value less than 1 for thisFrame , we must reset its
value to totalFrames for continuous counterclockwise motion. Once thisFrame has
been determined, we direct the object movie clip to go to and stop at the updated
frame value.
Save and test your movie. Press each arrow to make sure that the object rotates in
each direction properly. This completes the exercise. After the scripts from the last
chapter, this probably feels like child's play.
Tip 1: Remove the buttons and modify the script so that the object rotates clockwise
when the user presses down left of center of the object and counterclockwise when
pressing down right of center of the object. Open the file 8_1_objectVR2_DONE.swf
in the Completed_Exercises folder as a reference.
Tip 2: An alternative to pressing the mouse down is to simply move the mouse slowly
right or left to rotate the object clockwise or counterclockwise as demonstrated in 8_1_
objectVR3_DONE.swf . Be forewarned, the script is so short, it's disgusting.
Hint: using the modulo (%) function helps by eliminating the need for the if statements
that test the ends of the movie clip. Why is the 1 needed in the following line?
this.gotoAndStop( 1 + (framePos % totalFrames) )
Search WWH ::




Custom Search