Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-23-2003, 08:36 PM   #1
cajuntoast
Registered User
 
Join Date: Apr 2003
Posts: 3
Angry maximum size of text box?

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...

Thanks!

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.
Attached Images
File Type: gif scrollpaneprob.gif (10.4 KB, 563 views)
cajuntoast is offline   Reply With Quote
Old 04-26-2003, 03:14 PM   #2
retrotron
thinking is design
 
retrotron's Avatar
 
Join Date: Apr 2003
Location: UK
Posts: 1,292
Default

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):
ActionScript Code:
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):
ActionScript Code:
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:
ActionScript Code:
// 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,totalHeight); // 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:
ActionScript Code:
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!
retrotron
retrotron is offline   Reply With Quote
Old 04-26-2003, 07:13 PM   #3
tost
my pleasure
 
tost's Avatar
 
Join Date: Apr 2002
Location: gent.be
Posts: 792
Default

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:

yourScrollPane.refreshPane();

check out the files i posted in this thread, it's a scrollPane with text and images.

greetz
tost
tost is offline   Reply With Quote
Old 04-27-2003, 02:19 PM   #4
retrotron
thinking is design
 
retrotron's Avatar
 
Join Date: Apr 2003
Location: UK
Posts: 1,292
Default

Even easier. I don't suppose that works with scrollbars to . . . ?
retrotron is offline   Reply With Quote
Old 05-12-2003, 12:46 AM   #5
cajuntoast
Registered User
 
Join Date: Apr 2003
Posts: 3
Default

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/f...l/reader4.html
cajuntoast is offline   Reply With Quote
Old 05-12-2003, 01:32 AM   #6
retrotron
thinking is design
 
retrotron's Avatar
 
Join Date: Apr 2003
Location: UK
Posts: 1,292
Default

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.
retrotron is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:38 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.