Log in

View Full Version : Dynamic List - Limitting Size



jfreak53
03-08-2009, 02:16 AM
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?


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
03-09-2009, 02:01 AM
I figured it out. For anyone in the future looking for this, here is what I added:


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:


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");

Medyman
03-09-2009, 08:24 PM
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 (http://www.gskinner.com/blog/archives/2005/03/to__root_or_not.html) 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.