Creating a simple TLF TextContainerManager in Flex 4

by Peter deHaan on July 16, 2009

in TLF, TextLayoutFormat, beta1

The following example shows how you can create a simple TextContainerManager in Flex 4 using the Text Layout Framework (TLF) classes.

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 beta, check out the Adobe Flash Builder 4 page on the Adobe Labs site. To download the latest build of the Flex 4 SDK, see http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4. For instructions on using the beta Flex 4 SDK in Flex Builder 3, see "Using the beta Flex 4 SDK in Flex Builder 3".

package {
    import flash.display.Sprite;
 
    import flashx.textLayout.container.TextContainerManager;
 
    [SWF(width="550", height="300")]
 
    public class TextContainerManager_setText_test extends Sprite {
        public function TextContainerManager_setText_test() {
            var spr:Sprite = new Sprite();
            addChild(spr);
            spr.x = 40;
            spr.y = 50;
 
            var tcm:TextContainerManager = new TextContainerManager(spr);
            tcm.compositionWidth = 300;
            tcm.compositionHeight = 200;
            tcm.setText("(1)The quick brown fox jumps over the lazy dev. (2)The quick brown fox jumps over the lazy dev. (3)The quick brown fox jumps over the lazy dev. (4)The quick brown fox jumps over the lazy dev. (5)The quick brown fox jumps over the lazy dev.");
            tcm.updateContainer();
        }
    }
}

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.

{ 4 comments… read them below or add one }

1 Rob McKeown July 17, 2009 at 11:31 am

I must be missing something because this doesn’t appear to compile even when using the nightly (8654 build) SDK. I get several “Type was not found or was not a compile-time constant” errors pointing at TextBlock and TextLine as the missing classes.

Reply

2 Rob McKeown July 17, 2009 at 11:34 am

Ok… slightly embarrassed now. I forgot to change the required Flash player version to 10 in the projects properties.

Reply

3 Peter deHaan July 17, 2009 at 12:26 pm

Rob,

Out of curiosity, are you using Flex Builder 3, or Flash Builder 4 beta? If you are using FB4, it should correct the Player version automatically based on the current SDK version (unless you disabled that).

Peter

Reply

4 Rob July 22, 2009 at 7:30 pm

I was using Flex Builder 3. It’s good to know that Flash Builder will help me avoid forgetting that setting though.

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can 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

Previous post:

Next post: