View Full Version : maximum size of text box?

04-23-2003, 08:36 PM
I have this pesky reoccuring problem and I still haven't figured out a way to solve it. Here it goes:

My scrollpane contains movie clip that contains a text box. The reason I'm not just using a scrolling text box is that this movie clip will also dynamically generate a certain number of movie clips running down the side of the text. My problem is I can never make text box inside the movie clip long enough. I've tried setting the height manually and also dynamically (according to the amount of content) and it seems to have a fixed maximum. So it won't display all of my data! I've scoured the web and have found nothing. I'm guessing that the problem may be that movie clips have a maximum size. Any suggestions?

I've attached a screenshot in case my explanation was unclear. The scrollpane I'm having problems with can be seen on the left, with the red boxes. You can see how it cuts off on the bottom. If you're wondering what the heck that is, I'm trying to hone my XML/Flash skills by making something that displays XML journal archives...


P.S. This is my first post...I hope I'm not duplicating a question elsewhere, but I looked through for a while and didn't find this.

04-26-2003, 03:14 PM
I often have the same problem. What throws a wrench in the gears is that Flash puts the scrollpane (or scrollbar) on the stage and sets its properties before the contents of the scrollpane are loaded. Thus, the scrollpane/scrollbar will never scroll the length of a moviclip or a textfield if that _mc/_txt is generated dynamically at runtime. The way you have to work around this problem is to set the scrollpan/scrollbar properties after the content has been loaded/generated.

Using textfields can be pesky because the textField.getTextExtent() method is almost always unreliable. What I do is make a calculation based on how many characters there are in the text (text.length returns the number of characters). Of course, I have to guess how high the textfield will be based on the width, how many characters usually fit onto one line of text at that width (based on font size and spacing), and then how many vertical pixels each line will take up. This usually can take some time at first, tweaking the values of the calculating equation until your textfields all do justice to the dynamic text, but eventually you get it right. Here's what my code might look like to calculate this (based on arial, 11pt, in a textfield of 270px wide):

var myTxtLength = myTxt.length; // get character length for "myTxt"
var myTxtLines = (myTxtLength/60) + 3; // 60 characters per line, plus 3 extra lines just to be safe
var myTxtHeight = 15 * myTxtLines; // 15 pixels per line;
var thisTxtHeight = myTxtHeight; // this is the calculated height of the text
When you change the font, the font size, and how wide the text is, you'll have to tweak the values to get it right.

Then you can simply add up all the thisTxtHeight values (or, if the textfields are in individual movie clips, you can add up the heights of the movieclips) and get a totalHeight which you can use to manually set your scrollpane (e.g. each time you generate a textfield, include this line):

totalHeight = totalHeight + thisTxtHeight;
However, since you have a totalHeight, you can use a scrollbar and the myScrollbar.setScrollProperties() method to do this.

What I do is put all of my smaller movieClips or textFields into a larger movieClip (called "results_mc"). Then you simply set the scrollbar to move "results_mc" up and down. First you set the scrollbar properties:

// now we want to set the scrollbar to scroll the length of "results_mc"
var thumb = totalHeight/20; // make the width of the scrollbar "thumb" 1/20 of total height
myScrollbar.setScrollProperties(thumb,0,totalHeigh t); // set scrollbar's properties
myScrollbar.setChangeHandler("scroller"); // call the scroller() to control its movement
Notice that at the end I set the scrollbar to call a function called "scroller" whenever the scrollbar changes (e.g. when the user drags the "thumb" up or down). The scroller() function controls the movement:

function scroller() { // each time the scrollbar moves, perform this function
var position = myScrollbar.getScrollPosition(); // get current position
_root.results_mc._y = -position; // when scrollbar goes one way, results_mc goes the other
} // end scroller()
Then you have a scollbar that always scrolls through the text, no matter what the dynamic content or how many movieclips and/or textfields have been created. The trick is calculating the height of each textfield and -- as you are generating the textfields -- keeping a sum of how tall the stack of textfields is getting. Once you have that totalHeight, then you can do whatever you want with your scrollbar (or scrollpane, but the scrollpane seems more complicated for what you're trying to do).

Hope this helps!

04-26-2003, 07:13 PM
the solution could be very simple:
after you've built up the red buttons, use this code to adjust the scrollPane to the new content:


check out the files i posted in this thread (http://www.actionscript.org/forums/showthread.php3?s=&threadid=22470), it's a scrollPane with text and images.


04-27-2003, 02:19 PM
Even easier. I don't suppose that works with scrollbars to . . . ?

05-12-2003, 12:46 AM
Thanks so much for your help. I tried it quickly and it didn't work at first try, but I kind of forgot what I was doing code-wise since it's been so long. I have to get back into it and try to fix it. The file is here if anyone's interested: http://www.jerseygirlcreations.com/files/xml/reader4.html

05-12-2003, 01:32 AM
Very nice. Howe about posting the .fla so we can all check it out (unless you'd like to keep it for yourself :))? Or at least post the scrollbar code you used. I'm interested to see how you solved it.