To create a new instance of the Label class using ActionScript, drag a copy of the component from the Components panel into your current Flash document’s library. Next, import the fl.controls.Label class using the import statement. This step is required because the component files are not implicitly imported, like the other flash.* packages. Once you import the Label class into your current document, you can create a new Label instance using the new operator. Finally, add the new Label instance to the display list using the addChild() method.

Full code after the jump.

// ActionScript 3.0
import fl.controls.Label;
 
var myLabel:Label = new Label();
myLabel.text = "Hello world";
myLabel.move(10, 10);
addChild(myLabel);

For more information on the Flash/ActionScript 3.0 Label component, see the “Using the Label component” Flash Quick Start on Adobe.com.

Tagged with:
 

3 Responses to Creating a new Label instance using ActionScript 3.0

  1. For adding Labels in Action Script 3.0 it says the following:

    // ActionScript 3.0
    import fl.controls.Label;
     
    var myLabel:Label = new Label();
    myLabel.text = "Hello world";
    myLabel.move(10, 10);
    addChild(myLabel);

    But the fl.controls.Label is not available. I am using Flex Builder as IDE. Is there anything I am missing?

  2. Peter deHaan says:

    Raj Kumar Kundu,

    Sorry, I don’t know how you’d do this in Flex Builder. I was using Flash Authoring CS3/CS4 and you need to add a Label control to your document’s Library panel for this to work. I don’t know how you would be able to do that in Flex Builder.

    Peter

  3. Jeremy Hixon says:

    The library you would be wanting is:

    import mx.controls.Label;

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="" highlight="">

Spam Protection by WP-SpamFree