I need the text in an input TLF text field to be modified when the user changes it. As for example, I'm trying to make it uppercase every time the user adds or deletes a character:
import fl.text.TLFTextField;
import flashx.textLayout.formats.TextLayoutFormat;
import flashx.textLayout.elements.TextFlow;
var myTLFTextField:TLFTextField = new TLFTextField();
addChild(myTLFTextField);
myTLFTextField.x = 10;
myTLFTextField.y = 10;
myTLFTextField.width = 200
myTLFTextField.height = 100;
myTLFTextField.text = "This is my text";
var myFormat:TextLayoutFormat = new TextLayoutFormat();
myFormat.textIndent = 8;
myFormat.color = 0x336633;
myFormat.fontFamily = "Arial, Helvetica, _sans";
myFormat.fontSize = 24;
var myTextFlow:TextFlow = myTLFTextField.textFlow;
myTextFlow.hostFormat = myFormat;
myTextFlow.flowComposer.updateAllControllers();
//--
myTLFTextField.addEventListener(Event.CHANGE, this.onTextFieldChange);
function onTextFieldChange(event:Event):void
{
myTLFTextField.text = myTLFTextField.text.toUpperCase();
}
The code that goes before //--
is taken from the TLFTextField documentation, the very first example on the page.
When I try to edit the text, it does become uppercase, but after that the text field stops responding to any input and the output says
TypeError: Error #1009: Cannot access a property or method of a null object reference. at flashx.textLayout.container::TextContainerManager/getController() at flashx.textLayout.container::TextContainerManager/mouseDownHandler()
When I comment out the addEventListener
line, all appears to be working fine.
Does it mean that it's not possible to make changes to the text in a TLF text field on user input event like it is possible with the classic text fields?