Imageviewer with scroller and xml

Hi guys,

I tried to make a scrolling imageslider and when you click them the pane expands and opens the big picture… this works !

however the viewer I based it on had the urls for the jpegs hardcoded in the fla, so I thought let’s replace that with xml… (I left the original code in there, disabled with /*-marks)

and while the xml loads, the whole viewer thing doesn’t do nothing. I think I’m doing something wrong with the array-thing…

in the xml-file there are a few lines with data like this:
<?xml version=“1.0” encoding=“utf-8” standalone=“yes”?>
<images>
<pic>
<image>“beautifulfaces001”</image>
<caption>Kresge</caption>
</pic>
</images>

Can anybody look at this and tell me what to change…

actionscript


import mx.transitions.Tween;

// ************* Reading XML File for photos ***********
function loadXML(loaded){
	if(loaded) {
		xmlNode = this.firstChild;
		picnames = [];
		//caption = [];
		total = xmlNode.childNodes.length;
		for (i=0; i<total; i++) {
			picnames* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
			//caption* = xmlNode.childNodes*.childNodes[1].firstChild.nodeValue;
		}
		//firstImage();
	} else {
		content = "file not loaded !";
	}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("images.xml");
trace ("xml loading succesfull");

///


/*********  DECLARE AND INITIALIZE VARIABLES  **************************/
// names of folder and pictures, in the order to put them into the slider
/*var picnames:Array = [
  	"beautifulfaces001", 
  	"beautifulfaces002",
  	"beautifulfaces003",
	"beautifulfaces004",
	"beautifulfaces005",
	"beautifulfaces006"
	];
*/

// constants
var PICPATH:String = "photos/";	    // folder with jpgs
var NPICS:Number = picnames.length;	// number of pictures to load
var PICX:Number = 125;              // x loc of big picture
var PICY:Number = 0;                // y loc

var THUMBHOLDERX:Number = 10;       // x location of thumbnail holder movieclip
var THUMBHOLDERY:Number = 10;       // y location
var THUMBW:Number = 75;             // width of each thumbnail
var THUMBH:Number = 75;             // height
var THUMBHOLDERALPHA:Number = 75;   // alpha

var MARGIN:Number = 5;              // margin between thumbnails
var TOTALBYTES:Number = 5027462;     // approx sum of bytes in all jpgs (x 2)
var MAXPIXELS:Number = 6;          // max number of pixels to move slider per frame

// mask definition; mask is assumed to cover some part of the thumbnail slider (here the numbers
// were chosen so that there are margins between the mask and the right and left edges of the movie
// (which is 420 x 290), and enough space above and below the thumbs to show them when they 'grow'
// on mouseover
var MASKX:Number = 10;				// start x location of mask
var MASKW:Number = 100;				// mask width
var MASKY:Number = 10;				// start y location of mask
var MASKH:Number = 290;				// mask height

var totalloaded:Number = 0;         // running tally of bytes loaded from all pics

// index into pictures array, used for loading
var ipic:Number;

// set up loader, an instance of MovieClipLoader
var loader:MovieClipLoader = new MovieClipLoader();

// use the main timeline to listen to and respond to loader's broadcast events
loader.addListener(this);

/*********  DEFINE FUNCTIONS, INCLUDING INIT FOR MOVIE SETUP  **********/
// thumbnail rollover handler

function grow() {
   this.onEnterFrame = function() {
      if (this._width < THUMBW * 1.05) {
		 this._x -= this._width * .015;
         this._y -= this._height * .015;
         this._width *= 1.03;
         this._height *= 1.03;
		 this._alpha += 25;
      } else delete this.onEnterFrame;
   };
}

// thumbnail rollout handler

function shrink() {
   this.onEnterFrame = function() {
      if (this._width > THUMBW) {
         this._width /= 1.05;
         this._height /= 1.05;
         this._x += this._width * .025;
         this._y += this._height * .025;
 		 this._alpha -= 25;
      } else delete this.onEnterFrame;
   };
}

// function to move thumbnail slider ("this" = thumbs_mc)

function sliderControl() {
   var w:Number = this._height/2;
   var hw:Number = mask_mc._height/2;
   var npixels:Number;
   // only do when mouse over slider mask
   
   if (_xmouse > mask_mc._x && _xmouse < mask_mc._x + mask_mc._width) {
      // mouse over left half of slider:
      if (_ymouse > mask_mc._y && _ymouse < mask_mc._y + hw) {
         npixels = (hw - _ymouse) / hw * MAXPIXELS;
         this._y += npixels;
         if (this._y >= 0) this._y = this._y - w;
      // mouse over right half of slider:
      } else if (_ymouse > mask_mc._y + hw && _ymouse < mask_mc._y + mask_mc._height) {
         npixels = (_ymouse - hw) / hw * MAXPIXELS;
         this._y -= npixels;
         if (this._y <= -w) this._y = this._y + w;
      }
   }
}



// thumbnail click (onrelease) handler + opening window when clicking thumbnail

function openPic() {
   	//if the window is already out, run this code
	if (_root.windowUnit.window_mask._width>=_root.maskEndwidth) {		
		openPic;
		//if window is already retracted, run this code
	} else if (_root.windowUnit.window_mask._width<=_root.maskStartwidth) {
		//addText(viewerText);
		var extendWindow:Tween = new Tween(_root.windowUnit.window_mask, "_width", mx.transitions.easing.Strong.easeOut, _root.maskStartwidth, _root.maskEndwidth, _root.windowSpeed, true);
	}
    pic_mc.loadMovie(PICPATH + picnames[this.i] + ".jpg");
	//pic_mc.loadMovie(picnames[this.i]);
}

// assign event handlers (called when all jpgs are loaded)
function setupHandlers() {
   pct_txt.removeTextField();		// don't need loading indicator any more
   thumbs_mc.onEnterFrame = sliderControl;
   for (var i:Number = 0; i < NPICS*2; i++) {
      thumbs_mc["mc"+i].onRollOver = grow;
      thumbs_mc["mc"+i].onRollOut = shrink;
	  // onRelease > OpenPic but also open window..
	  thumbs_mc["mc"+i].onRelease = openPic;
   }
}

// listener function for broadcast 'done' message (for each pic)
// onLoadInit gets executed when the movieclip has been loaded into _mc AND 
//   its width and height data are available.
//   (_mc = the movieclip being loaded into)
// this routine sets the size and position of each thumbnail clip as its jpg
//   is loaded and starts the next one loading.  When all have been loaded, 
//   a random picture is loaded into pic_mc and setupHandlers is called to 
//   assign handlers to each thumbnail movieclip

function onLoadInit(_mc:MovieClip) {
   // this gets done when the jpg is completely loaded:
   _mc._width = THUMBW;
   _mc._height = THUMBH;
   _mc._alpha = 99;		// for image clarity
   // give the movieclip a property to remind it who it is
   // (used by openPic to know which big picture to open)
   _mc.i = (ipic >= NPICS ? ipic-NPICS : ipic);
	
   // add picture size to totalloaded variable
   totalloaded += loader.getProgress(_mc).bytesTotal;

   // now load the next one (if there are more) or set up handlers if done
   ipic++;
   if (ipic == NPICS * 2) {
      // start with a random photo displayed when all thumbs loaded
      pic_mc.loadMovie(PICPATH + picnames[Math.floor(Math.random()*NPICS)] + ".jpg");
	  //pic_mc.loadMovie(picnames[Math.floor(Math.random()*NPICS)]);
      setupHandlers();
   } else if (ipic >= NPICS) {
      // load jpg into duplicate thumbnail (will already be cached)
      loader.loadClip(PICPATH + picnames[ipic-NPICS] + ".jpg",  thumbs_mc["mc"+ipic]);
	  //loader.loadClip(picnames[ipic-NPICS],  thumbs_mc["mc"+ipic]);
   } else {
      // load jpg into thumbnail
      loader.loadClip(PICPATH + picnames[ipic] + ".jpg",  thumbs_mc["mc"+ipic]);
	  //loader.loadClip(picnames[ipic],  thumbs_mc["mc"+ipic]);
   }
}

// listener function to handle broadcast progress messages
// make pct_txt show cumulative loading progress

function onLoadProgress(_mc:MovieClip, loaded:Number) {
   var loadedsofar:Number = totalloaded + loaded;	
   pct_txt.text = Math.floor(loadedsofar / TOTALBYTES * 100) + "%";
}

function init() {
   // create holder for pictures
   createEmptyMovieClip("pic_mc", 1);
/*   pic_mc.beginFill(0,310);
   pic_mc.moveTo(0, 0);
      pic_mc.lineTo(310, 0);
   pic_mc.lineTo(310,310);
   pic_mc.lineTo(0, 310);
   pic_mc.endFill();
*/
   pic_mc._x = PICX;
   pic_mc._y = PICY;

   // create (and draw) holder for thumbnails 
   createEmptyMovieClip("thumbs_mc", 2);
   thumbs_mc.beginFill(0, 100);	// black
   thumbs_mc.moveTo(0, 0);
      thumbs_mc.lineTo(2 * (MARGIN + THUMBW) * NPICS, 0);
   thumbs_mc.lineTo(2 * (MARGIN + THUMBW) * NPICS, THUMBH);
   thumbs_mc.lineTo(0, THUMBH);
   thumbs_mc.endFill();
   // drawing the thumb holder at 0, 0 and then moving it makes its reg point = upper left
   thumbs_mc._x = THUMBHOLDERX;
   thumbs_mc._y = THUMBHOLDERY;
   thumbs_mc._alpha = THUMBHOLDERALPHA;

   // create, draw and enable mask over thumbs (could use different variables to define mask
   // if desired)
   createEmptyMovieClip("mask_mc", 3);
   mask_mc.beginFill(0x0000cc, 100);
   mask_mc.moveTo(0, 0);
   mask_mc.lineTo(MASKW, 0);
   mask_mc.lineTo(MASKW, MASKH);
   mask_mc.lineTo(0, MASKH);
   mask_mc.endFill();
   mask_mc._x = MASKX;
   mask_mc._y = MASKY;
   thumbs_mc.setMask(mask_mc);

   // create loading textfield indicator
   createTextField("pct_txt", 4, 200, 100, 40, 100);
   var tf:TextFormat = new TextFormat();
   tf.align = "center";
   tf.size = 12;
   tf.font = "Verdana";
   tf.color = 0xFFFF00;
   pct_txt.setNewTextFormat(tf);

   // make empty movieclips in thumbs_mc for each pic to go into
   // make double the number so the slider can move continuously and show content
   for (var i:Number = 0; i < NPICS * 2; i++) {
      var mc:MovieClip = thumbs_mc.createEmptyMovieClip("mc"+i, i+1);
      mc._x = 0;
      mc._y = i*(MARGIN + THUMBW);
   }
	
   // set the pointer to the first jpg in the array picnames
   ipic = 0;
   // start loading jpgs (ipic is initialized to 0)
   loader.loadClip(PICPATH + picnames[ipic] + ".jpg", thumbs_mc["mc"+ipic]);
   //loader.loadClip(picnames[ipic], thumbs_mc["mc"+ipic]);
}

/*********  CALL THE INIT FUNCTION TO START THE MOVIE  *****************/
init();