Anytime you need to display a lot of results, whether from a database, or, as in this tutorial's demo, from an XML file. In a full Flash site you generally have limited space in which to display data, but even if you are putting the results into a separate Flash movie, your space is still limited. Let's say you have a data set to display which includes images, a block of text, and a couple of buttons. Let's also say each result takes up 250 pixels of height. With the limit on a Flash movie's size being 2880 x 2880, vertically you'd only get 11 results to a single page.

The Demo Movie

The movie below feeds on 2 XML files containing the song data. I wanted the demo to make use of dynamically gathered data, and XML seemed to be the best choice under the circumstances. How you get your data is unimportant to the pagination concept, it's what we do with it afterward that counts. To see the flexibility of the class you can adjust the number of results to display.

The Demo Files

Now, download the file and let's dig into the code and see how this works.

The files included in the are and pagDemo.fla. This set of files shows the pagination working with both a top and bottom set of controls, while the and the pagDemoSingle.fla demonstrates the same class being used with only a single set of controls. The easyMusic.xml and rockMusic.xml files hold the data that we will be reading into the movie. And, you'll find the class and the class files inside the ca.xty.myUtils folder system.

The XML files are very simple examples, and so I hope they don't need any detailed explanation, because I'm not providing any. There are quite a few good tutorials about using Flash and XML and, to do the subject justice, I'd need to make this tutorial even longer than it is. Besides, you will most likely have much more complex data to work with in a real situation, and consequently a much more complex XML file. What I'll mainly be dealing with is gathering the data from the XML file and packaging it up in a way that's easy for us to use.

The has sections commented out to show you what gets left out when you are using a single set of controls, and beyond that everything else is exactly the same.

There is also a text file called backToTop.txt. This is a tiny bit of JavaScript that we will use together with the ExternalInterface class provided by Flash.

As usual, the fla's are empty, except for a button in the library and the fact that the Document Class property is set to PageDemo or PageDemoSingle.

What's not included in the zip file this time out is an fla for CS3 - but don't despair! Creating one is dead easy. Make a new fla in CS3 with a width of 500 and a height of 600. Drag a Button component into the library and set your Document Class to read either pagDemo or pagDemoSingle - remember, no .as extension, just the class name. Make sure you have all the files included in the zip in the same folder as your CS3 fla and you're good to go.

So let's jump into the file already!