Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts

    Dynamic List - Limitting Size

    I have a dynamic XML list that populates with pictures and text. What I want to do is right now it populates down. I want it to populate to the left then when it is 3 pictures wide go down a line and start all over from the left 3 more pictures and so on and so on. Here is my code that I am using right now to populate the list down, how do I make it do 3 wide then move?

    Code:
    var thumb_spacing = 154;
    
    // load variables object to handle loading of text
    var description_lv = new LoadVars();
    description_lv.onData = function(raw_text){
    	s = "";
    	if ( raw_text.indexOf( "\r" ) ) s = raw_text.split("\r").join("");
    	_root.student_page.student_txt.text = s;
    }
    
    function GeneratePortfolio(portfolio_xml){
    	var portfolioPictures = portfolio_xml.firstChild.childNodes;
    	for (var i = 0; i < portfolioPictures.length; i++){
    		var currentPicture = portfolioPictures[i];
    		var f = 0;
    		f++;
    		
    //this is where it starts populating the list with the xml items.
    
    		var currentThumb_mc = student_menu.menu_items.menu_pics.createEmptyMovieClip("thumbnail_mc"+i,i);
    		currentThumb_mc._y = i * thumb_spacing;
    		
    		currentThumb_mc.createEmptyMovieClip("thumb_container",0);
    		currentThumb_mc.thumb_container.loadMovie(currentPicture.attributes.image);
    		
    		var currentThumb_txt = student_menu.menu_items.menu_text.createEmptyMovieClip("text_mc"+i,i);
    		currentThumb_txt._y = currentThumb_mc._y + 100;
    		currentThumb_txt.createTextField("text_container",0,0,0,74,40);
    		
    		currentThumb_txt.text_container.multiline = true;
    		currentThumb_txt.text_container.type = "dynamic";
    		currentThumb_txt.text_container.selectable = false;
    		currentThumb_txt.text_container.embedFonts = true;
    		currentThumb_txt.text_container.wordWrap = true;
    		currentThumb_txt.text_container.border = false;
    
    		text_container_format = new TextFormat();
    		text_container_format.color = 0x000000;
    		text_container_format.font = "Arial";
    		text_container_format.size = 12;
    		text_container_format.bold = true;
    		text_container_format.align = "center";
    		
    		currentThumb_txt.text_container.setNewTextFormat(text_container_format);
    		currentThumb_txt.text_container.text = currentPicture.attributes.firstname+"\r"+currentPicture.attributes.lastname;
    		
    		currentThumb_mc.firstname = currentPicture.attributes.firstname;
    		currentThumb_mc.lastname = currentPicture.attributes.lastname;
    		currentThumb_mc.image = currentPicture.attributes.image;
    		currentThumb_mc.description = currentPicture.attributes.description;
    		
    		currentThumb_mc.onRelease = function(){
    			_root.student_page.student_image.loadMovie(this.image);
    			_root.student_page.name_text.text = this.firstname+" "+this.lastname;
    			description_lv.load(this.description);
    		}
    	}
    }
    
    // xml object for xml content (defines sources for selections)
    var portfolio_xml = new XML();
    portfolio_xml.ignoreWhite = true;
    portfolio_xml.onLoad = function(success){
    	if (success) GeneratePortfolio(this);
    	else trace("Error loading XML file"); // no success?  trace error (wont be seen on web)
    }
    // load
    portfolio_xml.load("5to.xml");

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    To do so you just need to have a variable keeping track of the rows and a height. This isn't tested, but gives you an idea where to go with it.

    Code:
    var thumb_spacing = 154;
    var thumb_height = 150; //Whatever the spacing needed
    
    // load variables object to handle loading of text
    var description_lv = new LoadVars();
    description_lv.onData = function(raw_text){
    	s = "";
    	if ( raw_text.indexOf( "\r" ) ) s = raw_text.split("\r").join("");
    	_root.student_page.student_txt.text = s;
    }
    
    function GeneratePortfolio(portfolio_xml){
    	var portfolioPictures = portfolio_xml.firstChild.childNodes;
            var row = 1;
            var thisrow = 0;
    	for (var i = 0; i < portfolioPictures.length; i++){
    		var currentPicture = portfolioPictures[i];
    		var f = 0;
    		f++;
    		
    //this is where it starts populating the list with the xml items.
    
                    if (thisrow > 3) {
                          thisrow = 1;
                          row++;
                    }
                    else {
                          thisrow++;
                    }
    		var currentThumb_mc = student_menu.menu_items.menu_pics.createEmptyMovieClip("thumbnail_mc"+i,i);
    		currentThumb_mc._x = thisrow * thumb_spacing;
                    currentThumb_mc._y = row * thumb_height;
    		
    		currentThumb_mc.createEmptyMovieClip("thumb_container",0);
    		currentThumb_mc.thumb_container.loadMovie(currentPicture.attributes.image);
    		
    		var currentThumb_txt = student_menu.menu_items.menu_text.createEmptyMovieClip("text_mc"+i,i);
    		currentThumb_txt._y = currentThumb_mc._y + 100;
    		currentThumb_txt.createTextField("text_container",0,0,0,74,40);
    		
    		currentThumb_txt.text_container.multiline = true;
    		currentThumb_txt.text_container.type = "dynamic";
    		currentThumb_txt.text_container.selectable = false;
    		currentThumb_txt.text_container.embedFonts = true;
    		currentThumb_txt.text_container.wordWrap = true;
    		currentThumb_txt.text_container.border = false;
    
    		text_container_format = new TextFormat();
    		text_container_format.color = 0x000000;
    		text_container_format.font = "Arial";
    		text_container_format.size = 12;
    		text_container_format.bold = true;
    		text_container_format.align = "center";
    		
    		currentThumb_txt.text_container.setNewTextFormat(text_container_format);
    		currentThumb_txt.text_container.text = currentPicture.attributes.firstname+"\r"+currentPicture.attributes.lastname;
    		
    		currentThumb_mc.firstname = currentPicture.attributes.firstname;
    		currentThumb_mc.lastname = currentPicture.attributes.lastname;
    		currentThumb_mc.image = currentPicture.attributes.image;
    		currentThumb_mc.description = currentPicture.attributes.description;
    		
    		currentThumb_mc.onRelease = function(){
    			_root.student_page.student_image.loadMovie(this.image);
    			_root.student_page.name_text.text = this.firstname+" "+this.lastname;
    			description_lv.load(this.description);
    		}
    	}
    }
    
    // xml object for xml content (defines sources for selections)
    var portfolio_xml = new XML();
    portfolio_xml.ignoreWhite = true;
    portfolio_xml.onLoad = function(success){
    	if (success) GeneratePortfolio(this);
    	else trace("Error loading XML file"); // no success?  trace error (wont be seen on web)
    }
    // load
    portfolio_xml.load("5to.xml");
    [/QUOTE]
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #3
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    Awsome! Got it working thanks for the help.


  •  

    Posting Permissions

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