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 http://www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see http://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.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

11 Responses to Adding an FTETextField object to the display list in Flex 4

  1. lee probert says:

    So this is just a low level TextField for rendering TextFlow text? Not heard of SpriteVisualElement either. Thanks.

  2. lee probert says:

    actually … can you not wrap the textfield in the SpriteVisualElement in MXML?

    • Peter deHaan says:

      @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

  3. Flex Boy says:

    [flexcoders] NFC (Near Field Communication) API in FlashPlayer 10.1
    Vote for this !!

    http://bugs.adobe.com/jira/browse/FP-2909

  4. CNA Trainings says:

    Thanks for the code! Thanks for sharing it with us!

  5. Jloa says:

    Nice one. Anyone knows how to adjust the 4sdk for FDT?

  6. gisdream says:

    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!

  7. gisdream says:

    sorry !it‘s the code that’s true:

    var myText1:String = “Here is an image we want to mainpulate:
    “;

  8. gisdream says:

    var myText1:String = “Here is an image we want to mainpulate:
    “;

  9. Aksahy says:

    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?

  10. Aksahy says:

    <–

    –>

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree