...

View Full Version : Dynamic List - Limitting Size



jfreak53
03-08-2009, 03:12 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");

gnomeontherun
03-08-2009, 05:47 PM
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.


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]

jfreak53
03-09-2009, 01:56 AM
Awsome! Got it working thanks for the help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum