Building a simple Picture Viewer:Part Two
In the previous exercise you used timeline navigation to move through the movie. As you may have discovered, this can be terribly inefficient. First off, if the movie is long, you will need to code each button in each frame to move to the next or the previous frame in the sequence. This leaves you wide open for a mistake. Secondly, gotoAndPlay(); can be used for this purpose but it is not quite the correct code for achieving the navigation objective. It does the job but there is a more efficient method of achieving the objective without all of the hand coding. Here's how:
- Open the file you created in the previous exercise.
- Select the "Next" button in Frames 3-5 of the Buttons layer .
- Right click on the key frame and select "Clear key frame."
- Select the "Next" button in Frame 2. and open the Actionscript Editor.
- Enter the following code:
on(press) {
nextFrame();
}
- Select the "Back" button in Frame 2 of the Buttons layer.
- Open the Actrionscript editor and enter the following code:
on(press){
prevFrame();
}
Those two functions- nextFrame() and prevFrame() - are ideal for sequential timeline navigation. What they do is to move the playbackhead to the next or the previous frame and stop it.
Image 1: The use of the NextFrame() and prevFrame() functions are ideal for sequential timeline navigation.
