|
-
Observe Alot By Watching
Hmmm getting textbox height of loaded XML?
Hi guys,
I will be here trying to figure this out all day so any posts will be much appreciated.
I've got my XML (content text) loading text into a text box, which is inside a movieclip.
Obviously the scroll parametres depend on the height of the loaded xml in proportion to the text inside the text box.
I need to rezize the textbox which is inside the MC to the size(height) of loaded text. Is there any way to make the textboxes height stretch to whatever is being loaded from the xml?
At the moment the textbox size always stays standard (to the size i make it on the stage). So the only way to solve it is to make it to the size of the largest text loaded, which is a pretty mickey mouse way of solving it.
I'll be right here if anybody knows a good way to do this. I was thinking to dynamically create this text box but where do I get the height???
Kind Regards
Ryan Mac
-
Observe Alot By Watching
Ha, wait I've got an idea...I'll post it if it works. By the way I'm using as2 flash 8
-
Observe Alot By Watching
I have managed to get my idea to work. You'll have to play around with it to get everything synched. It's quite simple. Calculate the number of characters in your XML content and make your calculations from there.
// calculate height of scrolltextbox---------------------------------
// define parametres of text box to be judged
// column width of box
column_width = 174;
// find out average character width
letter_width = 10;
// find out line height
letter_height = 17;
// tc...find out total characters in content from xml value
tc = this.location_text.length;
// cpl...get characters per line by divide column by average letter width
cpl = Math.round(column_width / letter_width);
// bh...divide total characters by characters per line muliptly by line height
bh = Math.round(tc/cpl) * letter_height;
trace(bh);
// end calculation--------------------------------------
Kind regards
Ryan Mac
-
you should try to use a monospace font. then you can calculate more exact... Did this on a html project for knowing if I hade to use a pop-up to display a longer message... you can see it att the front page of valdemarlethin.com (just find a entry that has a "Read more..."-link...
-
Observe Alot By Watching
Thanks BC...
Would be great if one could narrow it down to a finer detail, this way it will always depends on the type and size of font you are using. If I had some more time on this I would definitely get flash to figure out the calculation of height on the loaded text from the textbox first.
Kind regards
Ryan Mac
-
I'm looking for a similar solution. I have a button that is used about 50 times but with different text. I use an array to publish the button text to each new button. The problem is that the button text varies. I want to set the button background to the width of the text.
Your solution works but it's not as 'sexy' and simple as we would both like.
Are you defining the letter with and height or have you calculated that somehow based on the type of font you are using?
I'll keep searching for a cleaner answer. If I find it I'll let you know : )
-
To get the height of a text field in pixels:
trace(myText.textheight);
You could import your text into a text file (off stage) that has the same width dimensions you are looking for but with a really large height. Get the height of the text in this text window and now you have your height.
Or simpler yet. Make the original text box n width by 'really long depth' When you load the file you can then trace it's .textHeight and re-scale the text window to = the this.textHeight.
-
Observe Alot By Watching
Thanks Franclin,
This works like a charm...and is most definitely is the sexy way to do it!
-
Observe Alot By Watching
It gives you the exact height of the textbox which is all you actually need to make it work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|