Flex: accessing internal TextField methods of TextInput/TextArea
i am using a TextInput control in Flex. i want to get the x-y positions of the individual characters in the text field (making a text editor kinda thing with auto complete: i wanna place the drop down list at correct positions);
using the native flash.text.TextField, i can use getCharBoundaries method. But i am now trying to get hands on Flex and i would like to use mx.controls.TextInput/TextArea. Both of these controls don't have any of the native TextField methods [except getLineMetrics]. And the textField property that returns the internal TextField is protected (i can't see why Adobe is so 'protected' about internal text fields in Flex; in fl.controls.TextArea/TextInput, its available as public property; why would they make it protected in Flex?)
The question is, does anyone know of any way to get those x-y values without extending TextInput/TextArea classes?
writing a class [extending one of those] just to write a getter that returns textField instance seems.... i don't know; i feel like there may be an easier way to do it.
okay... i take it as a no. or is there anything i am missing?
Forget about getCharBoundaries, even caretIndex is not available in these classes. You have to extend TextInput class to get its caretIndex? it doesn't make sense to me. What is so dangerous about making a caretIndex public property in TextInput/TextArea?
why would they do that only in Flex? i mean fl.controls counterparts of these classes have a public textField property.
Use the mx_internal namespace to access the internal textField
You don't have to subclass the TextArea/TextInput class if your parent class/mxml makes use of the mx_internal namespace.
You'll notice in the TextArea class that the getTextField() method is scoped to mx_internal. To access this put the following code in your parent class:
import mx.core.mx_internal;
use namespace mx_internal;
now you should be able to access the TextField class in your TextArea via the following code:
that really helps
i ended up extending TextInput, but now i am gonna change it.
i wasn't aware there was a getTextField() method. mx_internal methods don't show up in the content assist also, making it difficult to find.
thanks a lot