Go Back   CodingForums.com > :: Client side development > Flash & ActionScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-08-2009, 03:12 AM   PM User | #1
jfreak53
Regular Coder

 
jfreak53's Avatar
 
Join Date: May 2004
Location: Guatemala
Posts: 477
Thanks: 19
Thanked 10 Times in 10 Posts
jfreak53 is an unknown quantity at this point
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");
jfreak53 is offline   Reply With Quote
Old 03-08-2009, 05:47 PM   PM User | #2
gnomeontherun
Senior Coder

 
gnomeontherun's Avatar
 
Join Date: Sep 2007
Location: Houston
Posts: 2,846
Thanks: 10
Thanked 238 Times in 229 Posts
gnomeontherun will become famous soon enoughgnomeontherun will become famous soon enough
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.
gnomeontherun is offline   Reply With Quote
Old 03-09-2009, 01:56 AM   PM User | #3
jfreak53
Regular Coder

 
jfreak53's Avatar
 
Join Date: May 2004
Location: Guatemala
Posts: 477
Thanks: 19
Thanked 10 Times in 10 Posts
jfreak53 is an unknown quantity at this point
Awsome! Got it working thanks for the help.
jfreak53 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:43 AM.


Advertisement
Log in to turn off these ads.