A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Dynamic XML image gallery

  1. #1
    Junior Member
    Join Date
    Feb 2006
    Posts
    3

    Dynamic XML image gallery

    Hi,
    I'm having a problem with my image gallery that you can see at www.xl70e3.com. For some reason preloader is not showing up for any of the images.

    This is the script:
    Code:
    import mx.transitions.*;
    
    _global.thisX = 37;
    _global.thisY = 150;
    
    _global.stageWidth = 700;
    _global.stageHeight = 310;
    
    var gallery_xml:XML = new XML();
    gallery_xml.ignoreWhite = true;
    gallery_xml.onLoad = function(success:Boolean) {
    	try {		if (success) {
    			var images:Array = this.firstChild.childNodes;
    			var gallery_array:Array = new Array();
    			for (var i = 0; i<images.length; i++) {
    				gallery_array.push({src:images[i].firstChild.nodeValue});
    			}
    			
    			displayGallery(gallery_array);
    		} else {
    			throw new Error("Unable to parse XML");
    		}
    	} catch (e_err:Error) {
    		trace(e_err.message);
    	} finally {
    		delete this;
    	}
    };
    
    gallery_xml.load("http://www.blablabla.com/123.xml");
    
    function displayGallery(gallery_array:Array) {
    	var galleryLength:Number = gallery_array.length;
    		for (var i = 0; i<galleryLength; i++) {
    
    		var thisMC:MovieClip = this.createEmptyMovieClip("image"+i+"_mc", i);
    		
    		mcLoader_mcl.loadClip(gallery_array[i].src, thisMC);
    				
    		preloaderMC = this.attachMovie("preloader_mc", "preloader"+i+"_mc", 5000+i);
    		
    		preloaderMC.bar_mc._xscale = 0;
    		preloaderMC.progress_txt.text = "0%";
    		
    		thisMC._x = _global.thisX;
    		thisMC._y = _global.thisY;
    		
    		preloaderMC._x = _global.thisX;
    		preloaderMC._y = _global.thisY+20;
    		
    		// if you've displayed 5 columns of images, start a new row.
    		if ((i+1)%7 == 0) {
    			// reset the X and Y positions
    			_global.thisX = 37;
    			_global.thisY += 80;
    		} else {
    			_global.thisX += 80;
    		}
    	}
    }
    
    var mcLoader_mcl:MovieClipLoader = new MovieClipLoader();
    var mclListener:Object = new Object();
    mclListener.onLoadStart = function() {
    };
    
    mclListener.onLoadProgress = function(target_mc, loadedBytes, totalBytes) {
    	var pctLoaded:Number = Math.round(loadedBytes/totalBytes*100);
    	var preloaderMC = target_mc._parent["preloader"+target_mc.getDepth()+"_mc"];
    	preloaderMC.bar_mc._xscale = pctLoaded;
    	preloaderMC.progress_txt.text = pctLoaded+"%";
    };
    
    mclListener.onLoadInit = function(evt:MovieClip) {
    	evt._parent["preloader"+evt.getDepth()+"_mc"].removeMovieClip();
    	var thisWidth:Number = evt._width;
    	var thisHeight:Number = evt._height;
    	var borderWidth:Number = 4;
    	var marginWidth:Number = 4;
    	evt.scale = 20;
    	evt.lineStyle(borderWidth, 0x000000, 100);
    	evt.beginFill(0xFFFFFF, 100);
    	evt.moveTo(-borderWidth-marginWidth, -borderWidth-marginWidth);
    	evt.lineTo(thisWidth+borderWidth+marginWidth, -borderWidth-marginWidth);
    	evt.lineTo(thisWidth+borderWidth+marginWidth, thisHeight+borderWidth+marginWidth);
    	evt.lineTo(-borderWidth-marginWidth, thisHeight+borderWidth+marginWidth);
    	evt.lineTo(-borderWidth-marginWidth, -borderWidth-marginWidth);
    	evt.endFill();
    	
    	evt._xscale = evt.scale;
    	evt._yscale = evt.scale;
    	evt.onPress = function() {
    		this.startDrag();
    		this._xscale = 100;
    		this._yscale = 100;
    		this.origX = this._x;
    		this.origY = this._y;
    		this.origDepth = this.getDepth();
    		this.swapDepths(this._parent.getNextHighestDepth());
    		this._x = 183;
    		this._y = 150;
    		mx.transitions.TransitionManager.start(this, {type:mx.transitions.Photo, direction:0, duration:1, easing:mx.transitions.easing.Strong.easeOut, param1:empty, param2:empty});
    	};
    	
    	evt.onRelease = function() {
    		this.stopDrag();
    		this._xscale = this.scale;
    		this._yscale = this.scale;
    		this._x = this.origX;
    		this._y = this.origY;
    	};
    	
    	evt.onReleaseOutside = evt.onRelease;
    };
    mcLoader_mcl.addListener(mclListener);
    There's gotta be something wrong in there that I just can't figure out...

    And another question, while we're at it.
    Is it possible to scale the pics down to some set size with automated cropping if required? So that both landscape and portrait-oriented pics would show up as say a 100x100 square? Not just by setting evt._height/width, because that screws up proportions. Maybe use part of the image and scale that down for the thumbnail? Kinda like at www.jkreps.com (check any of the photographers)... or are they creating buttons manually?

    Thanks in advance

  2. #2
    Junior Member
    Join Date
    Feb 2006
    Posts
    3
    Anyone?

    Would really appreciate any and all help... and sorry for the shameless bump

  3. #3
    Senior Member
    Join Date
    Mar 2003
    Posts
    316
    did you ever resolve the problem?

    I would like to build a dynamic photo gallery with preloaders ... so if you managed to get the code please post it

    thanks

  4. #4
    Junior Member
    Join Date
    Feb 2006
    Posts
    3
    Nope

    As you can see preloaders still aren't showing up and I never figured how to crop pics for thumbnails. Not that I've been working on it all this time... actually, you just reminded there is a problem.

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