Posted by: vodka on: March 13, 2007
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.
Sample Application | Dowload Source
ForthComing: Cursor locations to update on keyBoard navigation, HTMLText support [:)]
Why did you separate source file from SWF file? You could rely on attribute
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.
An adaptation of this makes it all possible… thanks!
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?
Thanks!
Good stuff… Just wanted to add that you can use the mx_internal command to access the protected text field, so you don’t have to subclass it.
i.e: [input component].mx_internal::getTextField().getCharIndexAtPoint(x,y)
March 22, 2007 at 1:57 pm
Do you have the source available still? Geocities reports that your site is down.
Thanks!
Ben