28 February 2008

extended Flash XML tutorial

flash menus, buttons and components

I really like video Flash tutorials at gotoAndLearn.com by Lee Brimelow. One of them is XML basics where you can learn quickly (in 15 minutes) how you can create simple dynamic XML driven Flash image gallery. You will probably need another 15-30 minutes to understand XML class properties like firstChild, childNodes and attributes but that depends on your previous experience.

Let's extend this tutorial a little bit. What I needed was just a small variation on Lee's gallery. Previous and next buttons change images from 0 index to array length index. When end is reached button don't do anything. I wanted to change this so when I reach last image in the array click on next button will bring me first image in the array and also, when first image is displayed click on the previous button will bring me last image in the array.

We just need to change code a little bit. Within onRelease function for previous button, "if" gets "else", so code looks like this:

whoIsOn = urls.length-1;
caption.text = captions[whoisOn];

Within onRelease function for next button, "if" also have some extra code:

whoIsOn = 0;
caption.text = captions[whoIsOn];

That's it, everything else is the same. Adding new images and altering XML file won't harm this code.




template by blogger templates