Hi there,
I wonder if anyone can help me out with this problem I have. I’m fairly experienced in flash but this I just can’t get my head around!
I’m trying to make a header of a webpage load random images from an xml file. This I can do fine but as the images are good quality they tend to take a while to load. Is there anyway that I can have a preloader appear when each file is loading?
This is how my code looks:
[FONT=Courier New]slideshow_xml = new XML();[/FONT]
[FONT=Courier New]slideshow_xml.load("images.xml");[/FONT]
[FONT=Courier New]slideshow_xml.ignoreWhite = true;[/FONT]
[FONT=Courier New]slideshow_xml.onLoad = parseXML;[/FONT]
[FONT=Courier New]var container_mc = this.createEmptyMovieClip("container", 0);[/FONT]
[FONT=Courier New]container_mc.createEmptyMovieClip("loader1_mc", 1);[/FONT]
[FONT=Courier New]container_mc.createEmptyMovieClip("loader2_mc", 2);[/FONT]
[FONT=Courier New]var mc_Loader1:MovieClipLoader = new MovieClipLoader();[/FONT]
[FONT=Courier New]var mc_Loader2:MovieClipLoader = new MovieClipLoader();[/FONT]
[FONT=Courier New]var listener1:Object = new Object();[/FONT]
[FONT=Courier New]listener1.onLoadInit = function() {[/FONT]
[FONT=Courier New] _root.loadedPic = picturePicker();[/FONT]
[FONT=Courier New] trace(_root.loadedPic);[/FONT]
[FONT=Courier New] mc_Loader2.loadClip(_root.loadedPic, container_mc.loader1_mc);[/FONT]
[FONT=Courier New] var fadeOut = new mx.transitions.Tween(container_mc.loader2_mc, "_alpha", mx.transitions.easing.Regular.easeOut, 1000, 0, 5, true);[/FONT]
[FONT=Courier New]};[/FONT]
[FONT=Courier New]mc_Loader1.addListener(listener1);[/FONT]
[FONT=Courier New]function fadeImageNext() {[/FONT]
[FONT=Courier New] mc_Loader1.loadClip(_root.loadedPic, container_mc.loader2_mc);[/FONT]
[FONT=Courier New]}[/FONT]
[FONT=Courier New]function parseXML(success) {[/FONT]
[FONT=Courier New] if (success) {[/FONT]
[FONT=Courier New] _global.imageArray = new Array();[/FONT]
[FONT=Courier New] var root = this.firstChild;[/FONT]
[FONT=Courier New] _global.numPause = Number(this.firstChild.attributes.timer*5000);[/FONT]
[FONT=Courier New] _global.order = this.firstChild.attributes.order;[/FONT]
[FONT=Courier New] _global.looping = this.firstChild.attributes.looping;[/FONT]
[FONT=Courier New] _global.fadetime = Number(this.firstChild.attributes.fadetime);[/FONT]
[FONT=Courier New] _global.xpos = Number(this.firstChild.attributes.xpos);[/FONT]
[FONT=Courier New] _global.ypos = Number(this.firstChild.attributes.ypos);[/FONT]
[FONT=Courier New] var childPtr = root.lastChild;[/FONT]
[FONT=Courier New] var count = 0;[/FONT]
[FONT=Courier New] while (childPtr.nodeName != null) {[/FONT]
[FONT=Courier New] imageData = new Object();[/FONT]
[FONT=Courier New] imageData.path = childPtr.attributes.path;[/FONT]
[FONT=Courier New] _global.imageArray[count] = imageData;[/FONT]
[FONT=Courier New] childPtr = childPtr.previousSibling;[/FONT]
[FONT=Courier New] ++count;[/FONT]
[FONT=Courier New] }[/FONT]
[FONT=Courier New] container_mc._x = _global.xpos;[/FONT]
[FONT=Courier New] container_mc._y = _global.ypos;[/FONT]
[FONT=Courier New] _root.loadedPic = picturePicker();[/FONT]
[FONT=Courier New] _root.fadeImageNext();[/FONT]
[FONT=Courier New] slideTimer = setInterval(_root.fadeImageNext, numPause);[/FONT]
[FONT=Courier New] }[/FONT]
[FONT=Courier New]}[/FONT]
[FONT=Courier New]function picturePicker() {[/FONT]
[FONT=Courier New] var nextPath = undefined;[/FONT]
[FONT=Courier New] if (_global.order == "random") {[/FONT]
[FONT=Courier New] while (randomNum == randomNumLast) {[/FONT]
[FONT=Courier New] randomNum = Math.floor(Math.random()*_global.imageArray.length);[/FONT]
[FONT=Courier New] }[/FONT]
[FONT=Courier New] nextPath = _global.imageArray[randomNum].path;[/FONT]
[FONT=Courier New] randomNumLast = randomNum;[/FONT]
[FONT=Courier New] } else if (_global.order == "sequential") {[/FONT]
[FONT=Courier New] if (p == undefined || p == _global.imageArray.length && _global.looping == "yes") {[/FONT]
[FONT=Courier New] p = random(imageArray.length);[/FONT]
[FONT=Courier New] } [/FONT]
[FONT=Courier New] nextPath = _global.imageArray[p].path;[/FONT]
[FONT=Courier New] p++;[/FONT]
[FONT=Courier New] } [/FONT]
[FONT=Courier New] if (nextPath != undefined) {[/FONT]
[FONT=Courier New] return nextPath;[/FONT]
[FONT=Courier New] }[/FONT]
[FONT=Courier New]}[/FONT]
I’ve also attacthed the xml file used for you experts to play around with. Please can someone out there help me? :sigh:
Mike