I want to write something in text area with keyboard(built in keyboard) and want to add something other from the keyboard made by me at the current cursor position.
Asked
Active
Viewed 1,427 times
1 Answers
1
Just use the TextArea's property
selectionActivePosition
Here is a working example.
//EDIT
To insert a new string into the textarea use String-functions like substr() and length(). After inserting you should change the current position of your cursor by adding the length of the inserted string.
EDIT//
Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<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"
minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
protected function onBtnInsert(event:MouseEvent):void
{
var str:String = "[new text]";
var pos:int = taMain.selectionActivePosition;
if (pos != -1)
{
taMain.text = taMain.text.substr(0, pos) + str + taMain.text.substr(pos, taMain.text.length - pos);
taMain.selectRange(pos + str.length, pos + str.length);
}
}
]]>
</fx:Script>
<s:VGroup x="20" y="20">
<s:TextArea id="taMain" width="200" height="150" text="I want to write something in text area with keyboard(built in keyboard) and want to add something other from the keyboard made by me at the current cursor position."/>
<s:HGroup verticalAlign="bottom">
<s:Button label="Get Pos" click="{laPos.text = taMain.selectionActivePosition.toString()}"/>
<s:Label text="Current position: "/>
<s:Label id="laPos"/>
</s:HGroup>
<s:Button label="Insert text" click="onBtnInsert(event)"/>
</s:VGroup>
</s:Application>

Anton
- 4,544
- 2
- 25
- 31
-
I have added a new function to insert a text – Anton Apr 17 '13 at 08:47
-
thanks for providing me the code.I have done same .First time on clicking at button text is inserted at current cursor position but when click second time cursor position is not changes and text is inserted at previous cursor position(means cursor position at the begining).suggest me correct way........... – Sunil486 Apr 18 '13 at 07:23
-
It works fine by me. May be I understand your case incorrect. Try to start my working example, I have added a new function to insert different values into the textarea. Let me know then, if it works well. – Anton Apr 18 '13 at 08:13
-
Concept was good and its working with little modification acccording to my application.Thanks sir – Sunil486 Apr 20 '13 at 05:20