Greetings all,
I am trying to build a simple image scroller in a way that it creates 2 arrays from 2 xml attributes. I got that working, but what I want to do next is randomize the order of the images and while making sure it they retain their specific urls. Then I want the scroller to loop those images in that random order infintely. So far here is my code:
stop();
import mx.transitions.Tween;
import mx.transitions.easing.*;
// change the values to alter the spacing and scroll speed
scrollSpeed = 1;
picSpacing = 0;
picWidth = 116;
currentX = 0;
currentThumbX=0;
// set the filename of xml
if (xmlFile == undefined) {
xmlFile = "xml/products.xml";
}
/***************************************
----XML Object definitions
*****************************************/
// the XML Object that will hold the information
var metrix_xml:XML;
metrix_xml = new XML();
metrix_xml.ignoreWhite = true;
//specify which function to handle on load event
metrix_xml.onLoad = listLoaded;
//read from xml file
var bigpicfiles:Array = new Array();
var productLinks:Array = new Array();
var numBigPics = 0;
var currentPic = 0;
//button actions
arrowBtn.onRollOver = function(){
var arrowRoll:Tween = new Tween(arrowBtn, "_alpha", Regular.easeOut, 100, 150, .2, true);
}
arrowBtn.onRollOut = function(){
var arrowRollout:Tween = new Tween(arrowBtn, "_alpha", Regular.easeOut, 150, 100, .2, true);
}
arrowBtn.onPress = function() {
var arrowPress:Tween = new Tween(arrowBtn, "_alpha", Regular.easeOut, 150, 100, .2, true);
scrollFunction();
};
//the callback function triggered by the XML onLoad event
function listLoaded():Void {
// get the first child: "thumbnails"
var mainNode:XMLNode = metrix_xml.firstChild;
var resourceCount:Number = mainNode.childNodes.length;
numBigPics = resourceCount;
trace(resourceCount);
for (var i = 0; i<resourceCount; i++) {
bigpicfiles* = mainNode.childNodes*.attributes.image;
productLinks* = mainNode.childNodes*.attributes.link;
}
setUpThumbs();
}
function setUpThumbs() {
for (var i = 0; i<numBigPics; i++) {
if (i>0) {
_root.productBox.productBox.product1.duplicateMovieClip("product"+(i+1),_root.productBox.productBox.getNextHighestDepth());
}
_root.productBox.productBox["product"+(i+1)].picHolder1.loadMovie(bigpicfiles*);
_root.productBox.productBox["product"+(i+1)].link = productLinks*;
// mouse actions
_root.productBox.productBox["product"+(i+1)].onRelease = function() {
getURL(this.link, "_self");
};
_root.productBox.productBox["product"+(i+1)].onRollOver = function() {
new Tween(this, "_alpha", Regular.easeOut, 100, 50, .2, true);
}
_root.productBox.productBox["product"+(i+1)].onRollOut = function() {
new Tween(this, "_alpha", Regular.easeOut, 50, 100, .2, true);
}
_root.productBox.productBox["product"+(i+1)]._x = picSpacing+(i*picWidth);
}
}
function scrollFunction() {
var boxTween:Tween = new Tween(productBox.productBox, "_x", Regular.easeOut, currentX, currentX-464, scrollSpeed, true);
currentX = currentX-464;
arrowBtn.enabled = false;
boxTween.onMotionFinished = function() {
arrowBtn.enabled = true;
};
}
/* Load the xml document. ----*/
metrix_xml.load(xmlFile);