A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Setting rows and columns in XML/Flash gallery?

  1. #1
    Junior Member
    Join Date
    Nov 2005
    Posts
    18

    Setting rows and columns in XML/Flash gallery?

    Hi,

    I have a gallery made in flash that loads its images using xml. At the moment when I call the images they load in one long row and go off the right of the screen, is there a way to have them load so that once it gets to eight images across it automatically puts the next images in a row underneath?

    Heres the code I have for now-

    Code:
    myPhoto = new XML();
    myPhoto.ignoreWhite = true;
    myPhoto.onLoad = function(success) {
    	//portfolioTag = this.firstChild;
    	numimages = this.firstChild.childNodes.length;
    	spacing = 110;
    	var numimages:Array = this.firstChild.childNodes;
    	for (i=0; i<numimages.length; i++) {
    		this.picHolder = this.firstChild.childNodes[i];
    		this.thumbHolder.id = i;
    		this.thumbHolder = thumbnails.createEmptyMovieClip("thumbnail"+i, i);
    		this.thumbHolder._x = i*spacing;
    		this.thumbLoader = this.thumbHolder.createEmptyMovieClip("thumbnail_image", 0);
    		this.thumbLoader.loadMovie(this.picHolder.attributes.thmb);
    		this.thumbHolder.title = this.picHolder.attributes.title;
    		this.thumbHolder.position = this.picHolder.attributes.position;
    		this.thumbHolder.main = this.picHolder.attributes.main;
    		this.thumbHolder.onRelease = function() {
    			tellTarget (_global._myTimeline) {
    			picture.loadMovie(this.main);
    			p = this.id-1;
    			desc_txt.text = this.title;
    			pos_txt.text = this.position;
    			unloadMovieNum(1);
    			}
    		};
    	}
    };
    myPhoto.load("xmlphoto.xml");
    Incase you're wondering about the other bits of code in here when you click the thumbnail it unloads this movie (which is on level1) and displays the larger version underneath.

    Any help with this would be appreciated as I haven't been able to find any threads/tutorials that cover it?

    Thanks!

    Tom

  2. #2
    Member
    Join Date
    Mar 2008
    Posts
    51
    I made a XML Photo Gallery , 1 week ago ...

    You can do something like this to set rows

    Code:
    myPhoto = new XML();
    myPhoto.ignoreWhite = true;
    myPhoto.onLoad = function(success) {
    	//portfolioTag = this.firstChild;
    	numimages = this.firstChild.childNodes.length;
    	spacing = 110;
            
            yspacing = 110;
            var Columns:Number = 5;
            var Column:Number = 1;
            var Row:Number = 1;
    	var numimages:Array = this.firstChild.childNodes;
    	for (i=0; i<numimages.length; i++) {
                    if(i == Columns*Row){
                            Row += 1;
                            Column = 0;
                    }
    		this.picHolder = this.firstChild.childNodes[i];
    		this.thumbHolder.id = i;
    		this.thumbHolder = thumbnails.createEmptyMovieClip("thumbnail"+i, i);
    		this.thumbHolder._x = Column*spacing;
                    this.thumbHolder._y = yspacing*Row;
    		this.thumbLoader = this.thumbHolder.createEmptyMovieClip("thumbnail_image", 0);
    		this.thumbLoader.loadMovie(this.picHolder.attributes.thmb);
    		this.thumbHolder.title = this.picHolder.attributes.title;
    		this.thumbHolder.position = this.picHolder.attributes.position;
    		this.thumbHolder.main = this.picHolder.attributes.main;
    		this.thumbHolder.onRelease = function() {
    			tellTarget (_global._myTimeline) {
    			picture.loadMovie(this.main);
    			p = this.id-1;
    			desc_txt.text = this.title;
    			pos_txt.text = this.position;
    			unloadMovieNum(1);
    			}
                    Column++
    		};
    	}
    };
    myPhoto.load("xmlphoto.xml");
    I am not so sure if this was exactly how ive done , cause my fla file is on pc in work .

    If you have problem , just ask

    EDIT: Columns var is number of Columns that you want , and yspacing is Space betwen rows
    Last edited by Pllum; 05-27-2008 at 02:10 PM.

  3. #3
    Member
    Join Date
    Mar 2008
    Posts
    51
    set Column and Row vars to 0

    Code:
    var Column:Number = 0;
    var Row:Number = 0;
    and in the if condition put this

    Code:
    if(i == Columns*(Row+1)){
               Row += 1;
               Column = 0;
    }
    now it should work

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