Flash AS3 - Setting a label's text contained in a movie clip

Associate
Joined
8 Aug 2008
Posts
302
You should add it programmatically, it will give you loads more control over it from within your Action Script

Code:
stop();
// Create a new MovieClip
var McTestMov:MovieClip = new McTest();
// Add the new MovieClip
addChild(McTestMov);
// Set the location of the new MovieClip to the middle of the stage
McTestMov.x = stage.stageWidth / 2;
McTestMov.y = stage.stageHeight / 2;
// Change the text in the label
McTestMov.labelText.text = "Testing...";

A good naming convention for a class is to start with a capital letter. Camel case works well for other items like text boxes.
 
Associate
Joined
8 Aug 2008
Posts
302
Hi RockLobster

No just use the movieclip the same way with the label already in it.

You can do it programatiically if you wanted, something along the lines of

Code:
stop();
// Create a new MovieClip
var McTestMov:MovieClip = new McTest();
// Add the new MovieClip
addChild(McTestMov);
// Set the location of the new MovieClip to the middle of the stage
McTestMov.x = stage.stageWidth / 2;
McTestMov.y = stage.stageHeight / 2;
// Create a new textfield
var LabelText:TextField = new TextField();
// Add the textfield to the movieclip
McTestMov.addChild(LabelText);
// Set the text of the textfield
LabelText.text = 'Hello World';
// Put a border on the textfield
LabelText.border = true;
// Registration point of the textfield is top left, centralise the textfield in the movieclip
LabelText.x -= LabelText.width / 2;
LabelText.y -= LabelText.height / 2;

should do it.

Hope that helps
 
Back
Top Bottom