Adding an FTETextField object to the display list in Flex 4

The following example shows how you can add an FTETextField object (formerly TLFTextField) by using a Halo/MX container and the rawChildren.addChild() method or by using a SpriteVisualElement object and the addChild() method.

The mx.core.TLFTextField class was renamed to mx.core.FTETextField in 4.0.0.10872.

Full code after the jump.

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.

For more information on getting started with Flex 4 and Flash Builder 4, see the official Adobe Flex Team blog.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/10/07/adding-an-ftetextfield-object-to-the-display-list-in-flex-4/ -->
<s:Application name="Spark_FTETextField_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/halo"
        initialize="init();">
 
    <fx:Script>
        <![CDATA[
            import mx.core.*;
 
            private function init():void {
                var fte:FTETextField = new FTETextField();
                fte.text = "Hello world";
                fte.border = true;
                fte.x = 10;
                fte.y = 10;
                parentObj.rawChildren.addChild(fte);
            }
        ]]>
    </fx:Script>
 
    <mx:Canvas id="parentObj" />
 
</s:Application>

Or you can add the FTETextField instance to the display list using a SpriteVisualElement object, as seen in the following example:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/10/07/adding-an-ftetextfield-object-to-the-display-list-in-flex-4/ -->
<s:Application name="Spark_FTETextField_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/halo"
        initialize="init();">
 
    <fx:Script>
        <![CDATA[
            import mx.core.*;
 
            private function init():void {
                var fte:FTETextField = new FTETextField();
                fte.text = "Hello world";
                fte.border = true;
                fte.x = 10;
                fte.y = 10;
                parentObj.addChild(fte);
            }
        ]]>
    </fx:Script>
 
    <s:SpriteVisualElement id="parentObj" />
 
</s:Application>

This entry is based on a beta version of the Flex 4 SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex 4 SDK.

11 thoughts on “Adding an FTETextField object to the display list in Flex 4

    1. @lee probert,

      FTETextField and UIFTETextField don’t seem to have MXML-tags, so I’m guessing they aren’t in the manifest or something (you also cannot do <mx:Alert /> and a couple other tags). Feel free to file a bug/enhancement if you think we should be able to do <s:FTETextField/> or <UIFTETextField/> — http://bugs.adobe.com/flex/.

      Peter

  1. hi !
    when i use the FTETextField object
    i find its tag “htmltext” that can’t be used normally
    please see it:

    protected function application1_creationCompleteHandler(event:FlexEvent):void
    {

    var myText1:String = “Here is an image we want to mainpulate: “;
    var txt:FTETextField=new FTETextField();
    txt.x = 10;
    txt.y = 10;
    txt.width = 250;
    txt.height = 250;
    txt.background = true;
    txt.border = true;
    txt.border = true;
    txt.multiline = true;

    txt.htmlText = myText1;
    var ui:UIComponent=new UIComponent();
    ui.addChild(txt);
    this.addElement(ui);

    }

    i can‘t get the image that’s included in the codes

    please tell me !can you send a message to my Email? thanks!

  2. Hi,
    I have a quick question and appreciate your view here
    Inside a state I am adding child as below

    Problem: even if I am using horizontal align they are not align to each other and they are coming one below another. Any suggestion on how may I align them horizontally?

Comments are closed.