Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First - you doing infinite loop in event listener! Your code in event handler invokes it selves! TLF.text = VALUE produce event like TLF.dispatch(new Event(Event.CHANGE));</p> <p>So <strong>add event listener to user actions not text change!</strong> E.g. for KEY_UP</p> <p>Second - correct formatting code so it will be applied to new text:</p> <pre><code>myTLFTextField.text = NEW_VALUE; myTextFlow = myTLFTextField.textFlow; myTextFlow.hostFormat = myFormat; </code></pre> <p>Edit: For more clarity I add full code:</p> <pre><code>import fl.text.TLFTextField; import flashx.textLayout.formats.TextLayoutFormat; import flashx.textLayout.elements.TextFlow; import flash.events.KeyboardEvent; var myTLFTextField:TLFTextField = new TLFTextField(); addChild(myTLFTextField); myTLFTextField.x = 10; myTLFTextField.y = 10; myTLFTextField.width = 400; myTLFTextField.height = 100; myTLFTextField.text = "This is my text"; myTLFTextField.type = "input"; //allow user to wirte in filed 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, wrongHandler); myTLFTextField.addEventListener(KeyboardEvent.KEY_UP, goodHandler); myTLFTextField.text = 'TEXT'; //this invoke CHANGE and trace '-' in console setTimeout(function(){ myTLFTextField.text = 'text';}, 500); //this invoke CHANGE and trace '-' in console function wrongHandler(event:Event):void { //myTLFTextField.text = myTLFTextField.text.toUpperCase(); //myTextFlow = myTLFTextField.textFlow; //myTextFlow.hostFormat = myFormat; // above code will run infinity loop of changing text! test it by uncomment and comment KEY_UP listener! trace('-'); // to see in console when and how many event was triggered } function goodHandler(event:Event):void { myTLFTextField.text = myTLFTextField.text.toUpperCase(); myTextFlow = myTLFTextField.textFlow; // reasign formating myTextFlow.hostFormat = myFormat; var i:uint = myTLFTextField.text.length; myTLFTextField.setSelection(i,i); // move carret to last sign trace('+'); // to see in console when and how many event was triggered } </code></pre> <p>Output:</p> <ol> <li>-</li> <li>-</li> </ol> <p>Output after writing 'a' character in field:</p> <ol> <li>-</li> <li>-</li> <li>-</li> <li>-</li> <li>+</li> <li>-</li> </ol> <p>Result on stage: TEXTA</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload