I put a TLFTextField on the stage, but I can not access it through the code

I tried to try TLF Text, because it is the default in Flash CS 5, but I can not perform the simplest task by changing its value. This works with the classic text box, but not with TLF:

import flash.display.MovieClip;

public class CumpleTiempos extends MovieClip
{

    public var t:TLFTextField;
    public function CumpleTiempos()
    {

        myText.text = "I'm a classic text"
    }
}

But not at all with TLF text, could you tell me how this was done, it is important to mention that TLF text should be created using Flash IDE, not code.

Thank,

+3
source share
2 answers

TLFTextField objects are not available for use in ActionScript until they are added to the scene.

Example (assumes a TLFTextField instance in the scene with the name "text"):

package  {
    import flash.display.*;
    import flash.events.*;

    public class Text extends Sprite {

        public function Text() {
            trace(text);

            this.addEventListener(Event.ADDED_TO_STAGE, _onAddedToStage);
        }

        private function _onAddedToStage($e:Event):void {
            trace(text);

            this.removeEventListener(Event.ADDED_TO_STAGE, _onAddedToStage);
        }

    }

}

Conclusion:

null
[object TLFTextField]
+3
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();

0

Source: https://habr.com/ru/post/1763956/


All Articles