Search code examples
apache-flexeventstextareaediting

Do not allow editing at sepecific area in text area in Flex


I just want to do not allow editing at some area of text area in flex. How it can be done?

let suppose text length in text area is 50 characters, i want to allow editing if cursor position is less than 15, and if cursor position in text area is greater than 15 it should not allow user to add more text in text area. If user press any key it should not add any character in text area.

I have used

event.preventDefault();
event.stopImmediatePropagation();
event.stopPropagation();

on key down event but it did not work for me.

Can any One help me? Thanks.


Solution

  • Maybe with use changing not change. I think this is what you want:

    <fx:Script>
        <![CDATA[
            import spark.events.TextOperationEvent;
    
            protected function textarea1_changeHandler(event:TextOperationEvent):void
            {
                trace("indexchange: ",ta.selectionActivePosition);
            }
    
            protected function ta_changingHandler(event:TextOperationEvent):void
            {
                trace("indexchanging: ",ta.selectionActivePosition);
                if(ta.selectionActivePosition>15) event.preventDefault();
            }
    
        ]]>
    </fx:Script>
    <s:TextArea id="ta" x="6" y="11" width="420" text="12345678901234567890" changing="ta_changingHandler(event)" change="textarea1_changeHandler(event)"/>