Hi there,
I have been following a tutorial to make an xml based gallery, just having a bit of a problem adding multiple lines of text to buttons which have been created dynamically.
I have set it up with a dynamic text box and button, which reproduce for every xml node, all good. When the text over runs the text box area, it creates a new line, which is great, the problem is the next button is created by adding a certain amount to the Y axis of the previous button, so there is overlap where the buttons have more than one line of text.
I sort of bodged a solution, by adding blank lines to the names below, eg
<?xml version=“1.0” encoding=“UTF-8”?>
<MENUS>
<MENU name=“Glass Book with Cat’s Whiskers” link="" description="" file=“lbook.swf”/>
<MENU name="
Glass Hand Tool with Cat’s Whiskers" link="" description="" file=“ltool.swf”/>
<MENU name="
Gold Broom" link=“http://www.slingshot.co.uk” description="" file=“lbroom.swf”/>
<MENU name="
Glass Plug" link="" description="" file=“lplug.swf”/>
<MENU name="
Glass Brush with Cat’s Whiskers" link="" description="" file=“lbrush.swf”/>
<MENU name="
Bronze Dress" link="" description="" file=“ldress.swf”/>
</MENUS>
but this messes with the button alignment, which starts according to the first line of the menu name, so for example the last button has 3 blank lines before it making the roll over miles away from the actual text.
I’ve tried putting /n
//n and <b> where I want the breaks but thats not working (used html text for the last one) do I need to add something else to the xml, or is it in the AS? I’m using as2, here is the (relevant) code :
function SS_Arrays() {
for (var count = 0; count < _root.projectCount; count++) {
var nodeObj = objXML.firstChild.childNodes[count];
namesArray[count] = nodeObj.attributes.name;
descriptionsArray[count] = nodeObj.attributes.description;
linksArray[count] = nodeObj.attributes.link;
filesArray[count] = nodeObj.attributes.file;
headLine.wordWrap = true;
}
// run the function to create the thumbnail and list view buttons
SS_createButtons();
}
////////////////////////////////////////////////////////////////////// ///////////////////
function SS_createButtons() {
// First of all we want to hide the master button on the stage (btn_projects_main)
// because we’ll be making duplicates of it in the next part of the function
_root.btn_projects_main._visible = 0;
// Work out the X and Y positions of the main button so our new buttons start in the same place
// (Which means where ever you position the main button is where the navigation will start).
btn_xPos = _root.btn_projects_main._x;
btn_yPos = _root.btn_projects_main._y;
// Set the distances between your buttons and the number of rows
btn_xDistance = 140;
btn_yDistance = 24;
btn_numOfRows = 25;
// This figure is used to work out when to start a new column of buttons
btn_yMax = btn_yPos + ((btn_numOfRows - 1) * btn_yDistance);
// Loop through the projects array and create a button for each one by duplicating the original.
for (count = 0; count < _root.projectCount; count++) {
duplicateMovieClip(_root.btn_projects_main, “btn_projects” + count, count);
// As the button is created, set it’s X, Y & text properties
_root[“btn_projects” + count]._x = btn_xPos;
_root[“btn_projects” + count]._y = btn_yPos;
_root[“btn_projects” + count].text = namesArray[count];
// set the X position for the next button
if(btn_yPos == btn_yMax){
// if the last buttons was the last row in the column (based on it’s Y position) then start a new column
// by resetting the Y position and adding 140px (btn_xDistance) to the the X position.
btn_xPos = btn_xPos + btn_xDistance;
btn_yPos = _root.btn_projects_main._y;
} else {
// if it’s not the last one in a row, simply move it along the Y axis.
btn_yPos = btn_yPos + btn_yDistance;
}
}
// Load the first project (number 0) to avoid an empty screen
SS_load_project(0);
// Make the first project button highlighted
tellTarget(_root.btn_projects0){
gotoAndPlay(3);
}
// Set the current button variable so we know which button to switch off when another one is pressed
_root.curButton = “0”;
}
Sorry if I’ve overloaded you with the text - I’m sure there must be a simple answer to this ?stion, I can post the files if that helps at all.