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.
{ 3 comments… read them below or add one }
For adding Labels in Action Script 3.0 it says the following:
But the fl.controls.Label is not available. I am using Flex Builder as IDE. Is there anything I am missing?
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
The library you would be wanting is: