Hi Matt,

Here is the solution for your problem - override set text method and
then measure the textHeight and change height accordingly.

NB This won't work if you want to print it. 

package
{
    import mx.controls.TextArea;
    import mx.core.ScrollPolicy;

    public class ElasticTextArea extends TextArea
    {
        public function ElasticTextArea()
        {
            super();
        }

        [Bindable("textChanged")]
        [NonCommittingChangeEvent("change")]
        override public function set text(value:String):void
        {
            verticalScrollPolicy = ScrollPolicy.ON;
            super.text = value;
            invalidateDisplayList();
            validateNow();
            super.height = super.textHeight;
            verticalScrollPolicy = ScrollPolicy.OFF;
        }
    }
}

Cheers,
Dmitri.




--- In [email protected], "Matt Davis" <[EMAIL PROTECTED]> wrote:
>
> I have an application that allows students to take practice
> standardized tests.  The test questions and answer options are
> displayed to the students on a Panel (the question is in on VBox and
> the answer options are in another VBox).  All of the test questions
> and possible answers are stored in an ArrayCollection.
> 
> Each question is displayed in the same TextArea and can vary greatly
> in its height needs.  Therefore, I would like the height of the
> TextArea to dynamically change each time the next question is loaded
> (the students click on a button to access the next question, which
> fires off a series of functions to get the next question and answer
> options from the ArrayCollection).
> 
> I have tried countless ways to change the height of the TextArea, all
> without any success.  I am hoping that there is something extremely
> obvious that I have missed.
> 
> This blog entry is about the best idea I have been able to find:
>
http://weblogs.macromedia.com/nwatson/archives/2005/09/dynamic_textare.cfm.
> However, I cannot figure out which event can successfully fire off the
> function when each question loads.  Perhaps I can call the function
> mentioned in this blog from my next() or back() functions (called when
> one of the buttons is clicked), but I don't know what to pass along
> when I call the function in order to make it work.
> 
> Here is the code for the VBox containing the question.
> 
> <mx:VBox id="vbQuestion" width="100%">
>                                       
> <mx:TextArea id="txtQuestion" htmlText="{currentQuestionSet.QUESTION}"
> width="100%" fontWeight="bold" wordWrap="true" editable="false"
> borderThickness="0" verticalScrollPolicy="off" />     
>                               
> <mx:Image id="img"
> source="/imageLibrary/images/{currentQuestionSet.QIMAGE}"
> horizontalAlign="center" />
> 
> </mx:VBox>
> 
> <mx:VBox .... code for answer options .... </mx:VBox>
> 
> <mx:ControlBar id="ctrlAppNav" width="100%" bottom="0">
> 
> <mx:Button label="Back" id="btnBack" click="back()"
> styleName="controlLeft"/>     
> 
> <... some other navigation buttons that do not apply to this problem
...>
>               
> <mx:Button label="Next" id="btnNext" click="next()"
> styleName="controlRight"/>
> 
> </mx:ControlBar>
> 
> Thanks,
> 
> Matt Davis
>


Reply via email to