ActionScript 3 vs Flex 3: Labels

Flex can’t do it all alone. While it’s possible to build a RIA in strictly ActionScript 3.0 or Flex 3’s MXML, sometimes you have to be familiar with both methods to get the best result.

In this post we’ll look at two ways of making one of the most common components in Flash and Flex development: the label.

The Actionscript 3 Way

The code below creates a label with size 24 font using with only actionscript in Flex. I’ve commented each line for easy reading:

For those of you with backgrounds in Flash – you’ll notice that we’re loading a different class for the label component. Flex uses the mx.controls.Label class instead of fl.controls.Label.

I’ve noticed a few compatibility issues resulting from the switch, so be aware that actionscript copied between Flash and Flex may require some tweaking to work.

The Flex 3/MXML Way

As expected, the MXML version is significantly more compact:

The demos here used minimal styling for the text output. For those interested in adding more variety, I’ll be putting up a post sometime soon on stylesheets with Flex that will help add some formatting to the equation. Subscribe to the feed and make sure you catch it!

Have any questions? Leave them in the comments and we’ll set you straight.

Posted Saturday, January 31st, 2009 · Back to Top


Add Comment

5 Comments 0 Mentions

  1. Wertha Author Editor

    I have a question. I have Flex 3.5 SDK and i can’t find the mx.controls, i change between 3.5 to 3.2 to 2.x and nothing every time that i type mx. the intellisense do not show controls, and if I type it by my own i got an error.


  2. Walker Author Editor

    It is a decent idea.


  3. Kavin Author Editor


    Can I use the setStyle() to set a label to Bold? How do I set my label property to Bold by default.



  4. monty Author Editor

    What is the max char/length is allowed in Label. If you try to insert more than 1lac length chars inside Label Flash player gets crashed. Any solution for that?


  5. ashok Author Editor

    Hi kavin,
    we can use setsyle method to bold a label setstyle(“fontweight”,bold)



Build Internet by One Mighty Roar. Since 2008.