Welcome to WebmasterWorld Guest from 18.104.22.168
Forum Moderators: open
I have 3 text boxes populated with different content from a php script. as the content of the text boxes is likely to change and be of different length, i would like to position them tightly underneath each other, e.g box 1 maybe one or two lines of text, and id like box two to position itself accordingly so as not to leave a big gap.
the instance names are : NAME, STUDIED and TEXT, and im using this script:
NAME.autoSize = true;
STUDIED.autoSize = true;
TEXT.autoSize = true;
//get the height of the the name box
var nameheight = getProperty (_root.targetmc.NAME, _height);
// and position studied box accordingly
setProperty (_root.targetmc.STUDIED, _y, nameheight);
//get hieght of studied box
var studiedheight = getProperty (_root.targetmc.STUDIED, _height);
// add name and studied heights together to get position for text:
var textpos = (studiedheight + nameheight);
setProperty (_root.targetmc.TEXT, _y, textpos);
it doesnt make any difference to the values of the positioning variables etc whther there is 1 or 2 lines of text filling the boxes<
I haven't tried mx 2004 yet ( only read up on it ), but the following code was written and tested with mx.
Edit the code as it suits your needs.
// placement of targetmc on the stage
_root.targetmc._x = 10;
_root.targetmc._y = 10;
// create array for text
strArr = ;
strArr = "blah blah blah blah blah blah blah ";
strArr = "blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah "
strArr = "blah blah blah"
// space between end of one textfield and start of another
spacer = 2;
// array for textfields
tArr = ;
tArr = _root.targetmc.NAME
tArr = _root.targetmc.STUDIED
tArr = _root.targetmc.TEXT;
// beginning placement within targetmc
startY = 0;
startX = 0;
curY = startY;
newY = undefined;
// loop thru all textfields to put text and placement
tArr[z].autoSize = true;
tArr[z]._x = startX;
tArr[z].text = strArr[z];
mHeight = tArr[z]._height;
newY = curY + tArr[z-1]._height + spacer;
tArr[z]._y = newY;
curY = newY;
Hope this helps.
Are you still using the setProperty method or simply stating the position in "dot" format as I used ( ie. targetmc.YOURTEXTBOX._y )?
As well, have you tried to trace your variables throughout your code to be sure they have the proper information and that the object to variable communication is correct ( ie. the object is being sent the correct variable if any at all )?
it seems to be taking the size from the boxes when they are initialised with blah blah, and then keeping that size when the text is loaded from the script, so they spread out properly, but if e.g. name wraps over 2 lines, it covers over the top of the 'studied' box.
strange to me too :(
Alternatively, you could add more to the spacer variable to make up the difference.
Hope it all works out for you in the end.