- Home
- Tutorials
- Flash
- Intermediate
- AS3 Photo Viewer Tutorial
AS3 Photo Viewer Tutorial

Parsing and Menu Generation
private function parseXML(event){
//generate the xml object
xml=new XML(event.target.data);
//ignorre the white spaces
xml.ignoreWhitespace=true;
//generate the xmlList object
xmlList=xml.img;
//init the image pos
imgPos=0;
//and the total image number
imgTotal=xmlList.length();
//add the menu holder to the stage
addChild(menuHolder);
//create a menu item variable
var menuItem:Sprite;
//and a textfield
var menuText:TextField;
//assign a new format for the text field
var format:TextFormat = new TextFormat();
format.font = "_sans";
format.color = 0xFFFFFF;
format.align='center';
format.size = 10;
//loop on the items to generate the menu
for(var i=0;i<xmlList.length();i++){
//the text field
menuText=new TextField();
//size fo the text
menuText.width=15;
menuText.height=15;
menuText.defaultTextFormat=format;
//set the text
menuText.text=i;//
//not selectable
menuText.selectable=false
//show border
menuText.border=true;
menuText.borderColor=0xFFFFFF;
//give it the name text
menuText.name="text";
menuItem=new Sprite();
//add it to the menu item
menuItem.addChildAt(menuText,0);
//
menuItem.x=i*(menuItem.width+10);
//draw the back ground ot use the backgroundColor text field proprety instead
menuItem.graphics.beginFill(0x333333,1);
menuItem.graphics.drawRect(0,0,menuItem.width,menuItem.height);
menuItem.graphics.endFill()
//disable the mouse children
menuItem.mouseChildren=false
//enable the button mode and use the hand cursor
menuItem.useHandCursor=true;
menuItem.buttonMode=true;
//add the on click event
menuItem.addEventListener(MouseEvent.CLICK,handleItemClick);
//add the menu item to the menu holder
menuHolder.addChild(menuItem);
}
//reupdate the position of the childs
resizeHandler(null);
//start loading the images one after one
loadNextImage();
}
as you can see the code is commented. the points of the parsing is that in AS3 you can generate the list directly from accessing the XML.SUBITEMNAME. and this will generate for you an XMLList object which you can access each item as an XML Object and you can also retrieve the number of items using the length() method.
lets examine the ImageContainer Class in the next Page.

