Use your arrow keys or press the green left and right arrows in the following animation to navigate through the photo gallery:
[ use your arrow keys or click on the green arrows to move through the gallery]
You will create something similar to the above animation in a short while.
Creating a Photo Gallery:
- Create a new movie in Flash MX. Set the width and height to anything you want.
Now, draw a rectangle the size of the images you will load and make it a movie clip. To convert something into a movie clip, select it and press F8. From the Convert to Symbol Dialog box that appears, select the Movie Clip option and press OK:
[ the convert to symbol dialog box ] - Once you have created your movie clip, select the movie clip with your mouse pointer. The Properties panel will display. Give the movie clip the instance name photo:
[ give the mc the name 'photo' in the instance panel ] - After you have done that, insert a new layer on your timeline. Right click on the blank keyframe on the new layer and select Actions. The Actions dialog box will appear.
Copy and paste the following code:
[ add the above lines of code to the empty keyframe ] - Would you believe me if I told you that you are done? You are, but to make it work, read on for customizing the photo gallery with your own images, image paths, etc.
Customizing the Photo Gallery Code
Now here comes the relatively simple part of customizing the code to work with your own pictures to make your photo gallery something more meaningful than 10 pictures of wildlife I found over at the National Geographic site. Make sure your Actions dialog box is displayed with the code you pasted and read on!
More than likely, you have your images stored in a certain location on your Web site or on your hard drive that is different from where your Flash animation is stored.
Find the first line of code (it is a variable actually) that says: this.pathToPics. Modify the path set by the aforementioned variable to the folder containing your images. For example, in the version of the code in the tutorial, the images are stored in the animation folder. Therefore, the variables pathToPics equals "animation/". If your images are stored in the SAME directory as your animation, simply make pathToPics equal "" as in:
this.pathToPics = "animation/";
Other examples of how you can modify the code include:
this.pathToPics = "../animation/";
this.pathToPics = "http://www.kirupa.com/pics/";
Now, you get the chance to specify the file name for the images that will be used! Find the line that says this.pArray. Replace all the image names I have written with the images that you will use instead. If you have more images than spaces provided, simply add more image names by adding a comma with the image name in quotation marks.
The code for just two images would be:
this.pArray = ["flash.jpg", "windows.jpg"];
Again, you can have as many or as few images in the photo gallery. The code that sbeener wrote is intelligent enough to count the number of images you specify in the pArray variable and customize the gallery accordingly.
You are done with customizing the code and this tutorial (for the second time). Preview the animation and see how it works. If you are good with ActionScript, you can tweak the code with a few modifications of your own.
Creating the Back and Forward Buttons
You have finished everything except the Back and Forward buttons. While this is optional, it is always nice to provide users a way of navigating your photo gallery without having to use the back and forward keys. To create the back and forward buttons, try the following steps:
- Draw the arrows or text that you choose to use for the back and forward buttons.
- Select a button and press F8. From the Convert to Symbol dialog box, select Button and press OK. Repeat this step for the other button.
- Right click on the button for "back" and select Actions. Add the following line of code:
- Similarly, right click on the button for "forward" and select Actions. Add the following line of code:
Rejoice! You have just completed your photo gallery tutorial (again) with the next and forward buttons.
discuss this topic to forum
