yarek
yarek

Reputation: 12054

how to keep N top lines in flex textare component?

My textarea component gets new lines with myTextArea (my TextArea is a SPARK component)

I want to keep only the last 50 lines. (no older lines are removed)

Any clue ?

Upvotes: 0

Views: 78

Answers (2)

Mahesh Parate
Mahesh Parate

Reputation: 786

Below code may give you some idea....

<?xml version="1.0"?>
<s:Application 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx">

    <s:layout> 
        <s:VerticalLayout/> 
    </s:layout>

    <fx:Script>
        <![CDATA[          

            [Bindable]
            private var initialDisplayText:String = "1\n2\n3\n4\n5\n6\n7\n8";

            private var maxLines:int = 8;

            private function arrangeTextHandler(event:KeyboardEvent):void
            {
                var count:int = 0;
                var displayString:String = "";
                var arrayTemp:Array = new Array();

                if(event.target.content.mxmlChildren.length > maxLines)
                {
                    for(var i:int = event.target.content.mxmlChildren.length-1; 0 <= i  ; i--)
                    {
                        for(var j:int = event.target.content.mxmlChildren[i].mxmlChildren.length-1; 0 <= j ; j--)
                        {
                            if(maxLines > count)
                            {
                                arrayTemp.push(event.target.content.mxmlChildren[i].mxmlChildren[j].text);
                                count ++;
                            }
                        }
                    }

                    arrayTemp.reverse();
                    for (var k:int=0; k<arrayTemp.length ;k++)
                    {
                        if(arrayTemp.length-1 != k)
                            displayString += arrayTemp[k] + "\n";
                        else
                            displayString += arrayTemp[k];
                    }

                    arrayTemp = null;
                    initialDisplayText = displayString;
                    myTextArea.invalidateProperties();
                }
            }

            private function onKeyEventDown(e:KeyboardEvent):void
            {
                if(myTextArea.textFlow.flowComposer.numLines > maxLines)
                {
                    arrangeTextHandler(e)
                }
            }

        ]]>
    </fx:Script>

    <s:TextArea id="myTextArea" text="{initialDisplayText}" 
                keyUp="onKeyEventDown(event)" height="500" width="100" x="50" y="50"/>

</s:Application>

Upvotes: 1

dvdgsng
dvdgsng

Reputation: 1741

According to this, there is no such property. You have to create your own component derived from TextArea.

Upvotes: 0

Related Questions