Small textarea enhancement

I met Avinash, Kislay and Amrit from sungard last sunday at the flex users meet organized by Mrinal and Abdul. John Koch, the APAC develper relations manager of Adobe was the main guest. Raghu, I and Sameer joined in from the flex team. Amidst a conversation, Amrit pointed out that he couldnt drop a text into a specific charecter location while doing a drag drop to a text area from a list or a similar source. The dropped text gets appended to the beginning or the end of the text. Seemed to me that some simple tricks would solve this issue.

There is a UITextField instance inside the TextArea control which is protected, Hence I had to extend the TextArea control to actually prototype this capability. So, here is a hacky first draft of the drop-at-cursor-location capability into a TextArea. Currently doesnt work with htmlText, that will come soon though. Thanks Sameer for the drag and drop tips.

How does it work?

Simple! After subclassing TextArea, on mouseUp, call the getCharIndexAtPoint() method of UITextField to find out the charecter index at the cursor position. Now, appending a text at that position is very simple.

Excellent. I’d been wondering how to determine where the cursor is for a while now- I’m making a crude spell checker for Flex and what would make it less crude is to be able to check a word at a time, whenever the space or newline key is hit.

This was very helpful – thanks!! I’m new to flex and I have an issue/question: i can’t seem to access the .text value of my text area to then save to a DB. I see the text that I dropped there, but I can’t access it via the text property. I’m guessing this has something to do with parent/child relationship?