Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random images from xml with no repeat 1

Status
Not open for further replies.

dmacster

Technical User
Jan 28, 2005
670
US
I've a client using the code from source from dominey, but the images sometimes overlap/repeat - so one image may load first several times, and some images may never get to the top position. How can I have this not repeat until all have been viewed.

Here's the AS - I'm still on MX since I do almost no Flash work.

Code:
// set random # variables - each must be 0 for first 'while' loop below
var randomNum = 0;
var randomNumLast = 0;

// parent container
var container_mc = this.createEmptyMovieClip("container",0);
// movie clip containers
container_mc.createEmptyMovieClip("loader1_mc",2);
container_mc.createEmptyMovieClip("loader2_mc",1);

// preload watcher
this.createEmptyMovieClip("watcher_mc",100);

// load xml
images_xml = new XML();
images_xml.ignoreWhite=true;
images_xml.onLoad = parse;
images_xml.load("[URL unfurl="true"]http://capegazette.com/showcaseNew/showcaseImages.xml");[/URL]

function parse(success) {
	if (success) {
		imageArray = new Array();
		var root = this.firstChild;
		_global.numPause = Number(this.firstChild.attributes.timer * 1000);
		_global.order = this.firstChild.attributes.order;
		_global.looping = this.firstChild.attributes.looping;
		_global.fadetime = Number(this.firstChild.attributes.fadetime);
		_global.xpos = Number(this.firstChild.attributes.xpos);
		_global.ypos = Number(this.firstChild.attributes.ypos);
		var imageNode = root.lastChild;
		var s=0;
		while (imageNode.nodeName != null) {
			imageData = new Object;
			imageData.path = imageNode.attributes.path;
			imageArray[s]=imageData;
			imageNode = imageNode.previousSibling;
			s++;
		}
		// place parent container
		container_mc._x = _global.xpos;
		container_mc._y = _global.ypos;
		// parse array
		imageArray.reverse();
		imageGen(imageArray);
	} else {
		trace('problem');
	}
}

// depth swapping
function swapPlace(clip,num) {
	eval(clip).swapDepths(eval("container_mc.loader"+num+"_mc"));
}

function loadImages(data,num) {
	if (i==undefined || i == 2) {
		i=2;
		createLoader(i,data,num);
		i=1;
	} else if (i==1) {
		createLoader(i,data,num);
		i=2;
	}
}
function createLoader(i,data,num) {
	thisLoader=eval("container_mc.loader"+i+"_mc");
	thisLoader._alpha=0;
	thisLoader.loadMovie(data[num].path);
	watcher_mc.onEnterFrame=function () {
		var picLoaded = thisLoader.getBytesLoaded();
		var picBytes = thisLoader.getBytesTotal();
		if (isNaN(picBytes) || picBytes < 4) {
			return;
		}
		if (picLoaded / picBytes >= 1) {
			swapPlace("container_mc.loader2_mc",1);
			thisLoader.alpha(_global.fadeTime,100);
			timerInterval = setInterval(imageGen,_global.numPause,data);
			delete this.onEnterFrame;
		}
	}
}
function imageGen(data) {
	// random, or sequential?
	if (_global.order=="random") {
		// choose random # between 0 and total number of images
		while (randomNum == randomNumLast) {
			randomNum = Math.floor(Math.random() * data.length);
			trace(randomNum);
		}
		loadImages(data,randomNum);
		randomNumLast = randomNum;
	} else if (_global.order=="sequential") {
		// start at 0, increment to total number of images, then drop back to zero when done
		if (p==undefined || p==data.length && _global.looping=="yes") { p=0; } else { break; }
		loadImages(data,p);
		p++;
	} else {
		trace ("order attribute in xml isn't correct - must specify either 'random' or 'sequential'");
	}
	clearInterval(timerInterval);
}
container_mc.onPress = function(){
getURL("[URL unfurl="true"]http://capegazette.powweb.com/listings.php",[/URL] "_top");
}
stop();

Thanks,
Donna
 
Umm - how do you shuffle the array? Do you know of a simple tutorial somewhere?

thanks,
donna
 
Thanks. I'll have to look to see if any can work with AS1.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top