For everyone out there, here is the final class that made the trick any
thoughts would be appreciated :). Also I checked out and it also does
the correct resizing using .htmlText property
Thanks Alex for the help.
package mylib
{
import mx.controls.TextArea;
import flash.text.TextField;
public class AdvancedTextArea extends TextArea
{
public function AdvancedTextArea() {
super();
this.verticalScrollPolicy="off";
this.horizontalScrollPolicy="off";
}
// The default size is the size of the text plus a 10 pixel margin.
override protected function measure():void {
super.measure();
var myTF:TextField=new TextField();
myTF.wordWrap=true;
myTF.text=text;
myTF.width=explicitWidth-10;
measuredHeight = measuredMinHeight = myTF.textHeight + 10;
}
}
}
Tracy Spratt wrote:
>
> Use that extended class exactly the same way you would use the base
> classs.
>
> <mx:Appliction …xmlns:com=”com.*” …
>
> …
>
> import com.AdvancedTextArea;
>
> …
>
> <com:AdvancedTextArea id="businesscase" width="100%" editable="false"
> selectable="false" borderStyle="none"/>
>
> Tracy
>
> ------------------------------------------------------------------------
>
> *From:* [email protected] [mailto:[EMAIL PROTECTED]
> *On Behalf Of *Mark
> *Sent:* Tuesday, September 11, 2007 2:26 PM
> *To:* [email protected]
> *Subject:* [flexcoders] Re: dynamic textArea sizing
>
> Thanks, yeah I saw that but I'm not sure how to now add this Class
> to the textArea component.
>
> So here's my Class (just like he had) -
>
> package com
> {
> import mx.controls.TextArea;
> import flash.text.TextLineMetrics;
>
> public class AdvancedTextArea extends TextArea {
> public function AdvancedTextArea() {
> super();
> }
> // The default size is the size of the text plus a
> 10 pixel margin.
> override protected function measure():void {
> super.measure();
>
> // Calculate the default size of the control based
> on the
> // contents of the TextArea.text property.
> var lineMetrics:TextLineMetrics = measureText(text);
> // Add a 10 pixel border area around the text.
> measuredHeight = measuredMinHeight =
> lineMetrics.height + 10;
> }
> }
> }
>
> Now how do I get this on the MXML?
>
> <mx:TextArea id="businesscase" width="100%" editable="false"
> selectable="false" borderStyle="none"/>
>
> Thanks
>
> --- In [email protected]
> <mailto:flexcoders%40yahoogroups.com>, "Alex Harui" <[EMAIL PROTECTED]> wrote:
> >
> > See this thread:
> >
> >
> >
> > ________________________________
> >
> > From: [email protected] <mailto:flexcoders%40yahoogroups.com>
> [mailto:[email protected]
> <mailto:flexcoders%40yahoogroups.com>] On
> > Behalf Of Mark
> > Sent: Tuesday, September 11, 2007 10:34 AM
> > To: [email protected] <mailto:flexcoders%40yahoogroups.com>
> > Subject: [flexcoders] dynamic textArea sizing
> >
> >
> >
> > Is there a way for the textArea to size its Height to fit the
> text, as
> > apposed to setting a height in pixels? I don't want the scroll
> bars
> > and it's no good for printing.
> >
> > Any examples out there?
> >
> > Thanks,
> > Mark
> >
> >
> >
> >
> > Using the Textfield made the trick I also set to off the scroll
> policies
> > so they wouldn't show
> > Thanks
> > Terius
> >
> > Alex Harui wrote:
> > >
> > > measureText doesn't know how to wordwrap.
> > >
> > > I would try: set the .text on the textField, set the textField's
> width
> > > to explicitWidth-10, and return the textHeight + 10 as the
> measuredHeight
> > >
> > > ----------------------------------------------------------
> -------
> > >
> > > *From:* [email protected]
> <mailto:flexcoders%40yahoogroups.com>
> [mailto:[email protected] <mailto:flexcoders%40yahoogroups.com>]
> > > *On Behalf Of *Guillermo Villasana
> > > *Sent:* Tuesday, September 11, 2007 6:50 AM
> > > *To:* [email protected] <mailto:flexcoders%40yahoogroups.com>
> > > *Subject:* [flexcoders] How to make TextArea resize to fit
> content
> > >
> > > Hello, I have been searching around to find out how to make
> htmlText (or
> > > Text if is used instead of htmlText) in TextArea to resize in
> height so
> > > that it won't make a scroll.
> > > This is what I was able to understand to achive the problem and
> > > generated this class:
> > >
> > > <code>
> > > package myclases
> > > {
> > > import mx.controls.TextArea;
> > > import flash.text.TextLineMetrics;
> > > public class AdvancedTextArea extends TextArea
> > > {
> > > public function AdvancedTextArea() {
> > > super();
> > > }
> > >
> > > // The default size is the size of the text plus a 10 pixel
> margin.
> > > override protected function measure():void {
> > > super.measure();
> > >
> > > // Calculate the default size of the control based on the
> > > // contents of the TextArea.text property.
> > > var lineMetrics:TextLineMetrics = measureText(text);
> > > // Add a 10 pixel border area around the text.
> > > measuredHeight = measuredMinHeight = lineMetrics.height + 10;
> > > }
> > > }
> > > }
> > > </code>
> > >
> > > then I use it in an action script like this:
> > >
> > > <code>
> > > pTextArea=new AdvancedTextArea();
> > > pTextArea.invalidateSize();
> > > pTextArea.width=300;
> > > pTextArea.text="a very very long text that should wrap around in
> a
> > > 300px width Text Area. This text is dynamic....;"
> > > myCanvas.addChild(pTextArea);
> > > </code>
> > >
> > > Still the TextArea will not resize it's height and the scrollbar
> > > appears, what am I doing wrong? How can I resize the pTextArea
> after the
> > > Text or htmlText property is set?
> > >
> > > Thanks for any help
> > > Terius
> > >
> > >
> >
> >
> >
> > --
> > Flexcoders Mailing List
> > FAQ:
> http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> <http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt>
> > Search Archives: http://www.mail-archive.com/flexcoders%
> <http://www.mail-archive.com/flexcoders%25>
> 40yahoogroups.com
> > Yahoo! Groups Links
> >
>
>
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/flexcoders/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/