dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: cs3 AS2 preloading all xml images before displaying

  1. #1

    cs3 AS2 preloading all xml images before displaying

    Hi eveyone,

    Just need some help preloading all the images listed in my xml.

    I've searched around and seem some other examples but nothing that I really can apply. The closest was from this forum but I got completely lost! (I'm obviously a designer rather than coder)

    Any help would be hugely appreciated.

    Code:
    //IMAGES
    
    function loadXML(loaded) {
    	if (loaded) {
    		xmlNode = this.firstChild;
    		image = [];
    		caption = [];
    		total = xmlNode.childNodes.length;
    		for (i=0; i<total; i++) {
    			image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
    			caption[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
    		}
    		firstImage();
    	} else {
    		content = "file not loaded!";
    	}
    }
    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.onLoad = loadXML;
    xmlData.load("../xmlfile.php");
    ///////////////////////////////////// 
    listen = new Object();
    listen.onKeyDown = function() {
    	if (Key.getCode() == Key.LEFT) {
    		prevImage();
    	} else if (Key.getCode() == Key.RIGHT) {
    		nextImage();
    	}
    };
    Key.addListener(listen);
    prevBt.onRelease = function() {
    	prevImage();
    };
    nextBt.onRelease = function() {
    	nextImage();
    };
    ///////////////////////////////////// 
    p = 0;
    this.onEnterFrame = function() {
    	filesize = picture.getBytesTotal();
    	loaded = picture.getBytesLoaded();
    	preloader._visible = true;
    	if (loaded != filesize) {
    		preloader.preload_bar._xscale = 100*loaded/filesize;
    	} else {
    		preloader._visible = false;
    		if (picture._alpha<100) {
    			picture._alpha += 2;
    		}
    	}
    };
    function nextImage() {
    	if (p<(total-1)) {
    		p++;
    		if (loaded == filesize) {
    			picture._alpha = 0;
    			picture.loadMovie(image[p], 1);
    			captions.text = caption[p];
    			picture_num();
    		}
    	}
    }
    function prevImage() {
    	if (p>0) {
    		p--;
    		picture._alpha = 0;
    		picture.loadMovie(image[p], 1);
    		captions.text = caption[0];
    		picture_num();
    	}
    	if (p<0){
    		prev._alpha = 0;
    	}
    	if (p>0) {
    		prev._alpha = 100;
    	}
    }
    function firstImage() {
    	if (loaded == filesize) {
    		picture._alpha = 0;
    		picture.loadMovie(image[0], 1);
    		captions.text = caption[0];
    		picture_num();
    	}
    }
    function picture_num() {
    	current_pos = p+1;
    	pos_txt.text = current_pos+" / "+total;
    }
    XML
    Code:
    <?xml version="1.0"?>
    <images>
    <pic>
    <image>Arch_10.jpg</image>
    <caption>yadda yadda yadda</caption>
    </pic>
    <pic>
    <image>Arch_11.jpg</image>
    <caption>more yadda yadda</caption>
    </pic>
    <pic>
    <image>Arch_46_47.jpg</image>
    <caption>yadda yadda again</caption>
    </pic>
    </images>

  2. #2
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    This should put you on the right track:

    http://board.flashkit.com/board/show...loading+images
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  3. #3
    Thanks heaps silentweed,

    I'll have a look.

    I had applied another solution but it was a bit hit and miss.

    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center