homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Flash and Shockwave
Forum Library, Charter, Moderator: open

Flash and Shockwave Forum

dynamic text boxes in flash mx2004
setting position relevent to content

 2:32 pm on Nov 3, 2003 (gmt 0)

using: mx2004 but would like to publish as flash 6.

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<

any pointers?



 4:36 pm on Nov 3, 2003 (gmt 0)

Hiya, Ben.

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[0] = "blah blah blah blah blah blah blah ";
strArr[1] = "blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah "
strArr[2] = "blah blah blah"

// space between end of one textfield and start of another
spacer = 2;

// array for textfields
tArr = [];
tArr[0] = _root.targetmc.NAME
tArr[1] = _root.targetmc.STUDIED
tArr[2] = _root.targetmc.TEXT;

// beginning placement within targetmc
startY = 0;
startX = 0;
curY = startY;
newY = undefined;

// loop thru all textfields to put text and placement
for(z=0;z<=tArr.length-1;z++) {
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.



 5:23 pm on Nov 3, 2003 (gmt 0)

it kind of works but has the same problem as the original code i posted, i.e. the boxes are fixed in position irrespective of whther the box above has 1, 2 or 3 lines, so sometimes theres a gap, and some times an overlap.



 6:01 pm on Nov 3, 2003 (gmt 0)

That seems odd to me.
When I tested the code I posted, I created the textboxes inside targetmc in a scattered formation so I could be sure the placement worked. Also, I made the textboxes fairly short to ensure they had varrying line amounts.

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 )?


 7:16 pm on Nov 3, 2003 (gmt 0)

no not using setProperty, pretty much the code as posted.

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 :(



 9:50 pm on Nov 3, 2003 (gmt 0)

If the alignment still doesn't work out for you, you could always set the textfields as mc's and load them dynamically as needed with duplicateMovieClip ( or use createTextField ) and just get the height of targetmc before the next textfield is created.
I've used that method before as well and it works since the textfields are inside the container you simply have to get the height of targetmc before the next textfield is created.

Alternatively, you could add more to the spacer variable to make up the difference.

Hope it all works out for you in the end.



 10:03 pm on Nov 3, 2003 (gmt 0)

thanks for your input, winstun - ill try again tommorrow.

welcome to webmasterworld! :)


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Flash and Shockwave
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved