views:

101

answers:

2

Hi, I tried to give a try to the TLF Text, because it's the default in Flash CS 5, but I can't accomplish the simplest task, change its value. This works with a classic textbox, 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 please tell me how it's done, it's important to mention that the TLF Text has to be created with the Flash IDE, not by code.

Thanks,

A: 
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();

via

Eugene
I want to use a textfield "drawn" with the IDE, not added with addChild(myTLFTextField);
MrAn3
A: 

TLFTextField objects are not available for use in Actionscript until they have been added to the stage.

Example (assumes a TLFTextField instance on stage with name of "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);
        }

    }

}

Output:

null
[object TLFTextField]
findzen