-
Determining the length of text in a textfield?
I have a 200 pixel wide text field that will be populated with some dynamic text. I would also like to have this text be underlined so that it resembles a HTML link.
How can I determine the length of the dynamic text so that I can resize the underline to match?
Thanks in advance.
Last edited by Danger Madcow; 01-19-2005 at 08:46 PM.
-
Is this a dumb question or a brain teaser?
-
World Kit Vote Holder
Code:
trace(myTextField.length())
-
Sure about those ()
trace(myTextField.length);
-
Originally posted by oldnewbie
Sure about those ()
trace(myTextField.length);
This worked, without the "()".
What a wonderfully simple answer to my question. Thanks for the help, guys.
-
yep that works, but is it possible to get the length in pixels?
-
It's not pretty but ryanmacflashkit has a solution at http://board.flashkit.com/board/show...11#post3825311
By calculating the (average font width*#length of the string)= the pixel width.
-
To get the length in pixels:
trace(myText.textWidth);
This sipmple line of code will trace the width of the text field.
-
Flashmatics
why do u need to know the length at all? just use html tags e.g
Code:
this.createTextField("tMessage", 1, 100, 100, 200, 50);
tMessage.autoSize = true;
tMessage.html = true;
tMessage.htmlText = "<u><a href='http://www.hotmail.com'>This is a link to hotmail</a></u>"
-
yes it's true I can easily create a text field to a specific dimension. But that's not what I'm doing.
I have over 50 buttons on the stage. I don't want to be placing them on the stage one by one. Instead I have a master button_mc that contains text and an underline. (along with a few other possible rollover animations. – bullets, background colour ect.) First I place the buttons on stage using attach movie. Then I turn all of the bullets, backgrounds an undelines to a width or a _visible of 0.
Then using an Array I push text into each button. Since I don't know the length of some of these buttons. I have created a long text field inside the button. onRollover the underline expands to the width of... the text. Not the text field and not the button_mc. all of which are longer than the text.
textWidth works like a charm. THANKS
textHeight has also helped me to create an animated background for text that is two or three lines deep.
Ps checked out your site. Great job.
-
Flashmatics
..glad u like my site...
the above textfield in the example does not have a specific dimension, it grows to accommodate whatever text is put in it..
anyway as well as u got it sorted, all is good !!....
-
Getting text to resize isn't really my problem. Although that does help keep it clean.
I'm animating objects under the text. Think of a hint button. rollOver an object and the 'hint' function is invoked. That function attaches the hint_mc to the stage. It then calls an array and publishes the appropriate array text inside the hint_mc. The background of the array is equal to the width of the text plus a bit of padding. Done.
Without textWidth I was having to make backgrounds equal to the longest string in the Array. Not so nice.
Thanks!
-
Dear Mad Cow, Sorry I got off track in your thread. Since you want to make an underline in your Dynamic text why don't you use CSS. Use this to controll your dynamic text.
p {
font-size: 9px;
font-family: Verdana, Arial, Helvetica, sans-serif;
text-decoration: none;
color: #FFFFFF;
margin-left: 5px;
margin-right: 5px;
}
a {
color: #EC3A00;
text-decoration: none;
}
a:hover {
color: #F54500;
text-decoration: underline;
}
Here is a simple tutorial on flash and CSS: http://www.kirupa.com/developer/mx2004/css.htm
-
I've used textWidth property and it worked verywell,then while continue working in .fla file it failed to give me the right value!!!!
it gave me a wrong value than the real value of textWidth?!
does anyone know why?
-
Question
are you in As2? Is the difference consistent?
-
textwidth failed unreasonable
Yes,I'm in As2?
And difference is inconsistent at all! sometimes it's read right sometimes it's not .
could size of window (shown part of stage) affect the size of textwidth?!,if so,How can I fix it?!
-
I think the problem was with the size of the window of swf.
my function only works well if stage.scaleMode="showAll"; inorder to read textWidth value in properway,but since my final code will be published at html, it doesn't work at all.
it always fail to read proper value for textwidth?!!!
I don't know what to do!
any suggestions.!?
-
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
|