Results 1 to 3 of 3

Thread: Dynamic List - Limitting Size

  1. #1
    Join Date
    Jan 2008
    Posts
    42
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default 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. #2
    Join Date
    Jan 2008
    Posts
    42
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default

    I figured it out. For anyone in the future looking for this, here is what I added:

    Code:
    var thumb_height = 150; //Whatever the spacing needed
    var row = 0;
    var thisrow = 0;
    
    if (thisrow > 2) {
                          thisrow = 1;
                          row++;
                    }
                    else {
                          thisrow++;
                    }
    
    currentThumb_mc._x = thisrow * thumb_spacing - 85;
    currentThumb_mc._y = row * thumb_height;
    And this is my new code where I added it at:

    Code:
    var thumb_spacing = 85;
    var thumb_height = 150; //Whatever the spacing needed
    var row = 0;
    var thisrow = 0;
    
    // 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];
    		
    		if (thisrow > 2) {
                          thisrow = 1;
                          row++;
                    }
                    else {
                          thisrow++;
                    }
    				
    		var currentThumb_mc = student_menu.menu_items.menu_pics.createEmptyMovieClip("thumbnail_mc"+i,i);
    		//currentThumb_mc._y = i * thumb_spacing;
    		currentThumb_mc._x = thisrow * thumb_spacing - 85;
            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._x = currentThumb_mc._x;
    		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.onRollOver = currentThumb_mc.onDragOver = function(){
    		//	info_txt.text = this.title;
    		//}
    		//currentThumb_mc.onRollOut = currentThumb_mc.onDragOut = function(){
    		//	info_txt.text = "";
    		//}
    		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");

  3. #3
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Glad you got it figured out, jfreak53. I see that you're using _root in a few places. It shouldn't cause trouble with your code, but it's important to understand what is implied by that keyword. This article by Grant Skinner explains the implications of _root.

    It's not necessarily wrong to be using _root, but if you find yourself using it too much, it's probably indicative of larger problems in your code.

Bookmarks

Posting Permissions

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