Click to See Complete Forum and Search --> : Flash image loading from XML file


gauravkhanna28
06-16-2010, 10:27 AM
In the below code images are displaying randomly from xml in flash into 4 different movieclips. What exactly i require is that the not 2 or more image should not be same when displaying in the blocks.
========================================
import mx.transitions.Tween;
import mx.transitions.easing.*;

pauseTime = 2000;

xmlImages = new XML();
xmlImages.ignoreWhite = true;
xmlImages.onLoad = loadImages;
xmlImages.load("image.xml");

function loadImages(loaded) {
if (loaded) {
xmlFirstChild = this.firstChild;
imageFileName = [];
totalImages = xmlFirstChild.childNodes.length;
trace(totalImages);
for (i=0; i<totalImages; i++) {
imageFileName[i] = xmlFirstChild.childNodes[i].firstChild.nodeValue;
}
randomImage();
}
}
function randomImage() {
//if (loaded == filesize) {
//trace(totalImages);
var ran_a = Math.round(Math.random() * (totalImages - 1));
var ran_b = Math.round(Math.random() * (totalImages - 5));
var ran_c = Math.round(Math.random() * (totalImages - 10));
var ran_d = Math.round(Math.random() * (totalImages - 15));

picture_mc._alpha = 0; // Start image clip as invisible
picture_mc.loadMovie(imageFileName[ran_a], 1); //Load random image from xml
picture_mc2._alpha = 0;
picture_mc2.loadMovie(imageFileName[ran_b], 1); //Load random image from xml
picture_mc3._alpha = 0;
picture_mc3.loadMovie(imageFileName[ran_c], 1); //Load random image from xml
picture_mc4._alpha = 0;
picture_mc4.loadMovie(imageFileName[ran_d], 1); //Load random image from xml
var pictureTweenIn:Tween = new Tween (picture_mc,"_alpha",Normal.easeIn,0,100,1,true); // Use the Tween class to ease in the alpha from 0 to 100 over 1 seconds
var pictureTweenIn:Tween = new Tween (picture_mc2,"_alpha",Normal.easeIn,0,100,2,true); // Use the Tween class to ease in the alpha from 0 to 100 over 1 seconds
var pictureTweenIn:Tween = new Tween (picture_mc3,"_alpha",Normal.easeIn,0,100,3,true); // Use the Tween class to ease in the alpha from 0 to 100 over 1 seconds
var pictureTweenIn:Tween = new Tween (picture_mc4,"_alpha",Normal.easeIn,0,100,1,true); // Use the Tween class to ease in the alpha from 0 to 100 over 1 seconds
pictureTweenIn.onMotionFinished = function () { // When done fading
_root.pause(); // Start pause() function
}
//}
}
function pause() {
myInterval = setInterval(pause_slideshow, pauseTime);
function pause_slideshow() {
clearInterval(myInterval);
var pictureTweenOut:Tween = new Tween (picture_mc,"_alpha",Normal.easeOut,100,0,1,true); // After pause, start fade out
var pictureTweenOut:Tween = new Tween (picture_mc2,"_alpha",Normal.easeOut,100,0,2,true); // After pause, start fade out
var pictureTweenOut:Tween = new Tween (picture_mc3,"_alpha",Normal.easeOut,100,0,3,true); // After pause, start fade out
var pictureTweenOut:Tween = new Tween (picture_mc4,"_alpha",Normal.easeOut,100,0,1,true); // After pause, start fade out
pictureTweenOut.onMotionFinished = function () { // Once faded out
_root.randomImage(); // Call next randomImage()
}
}
}