0
votes

I first added a movieClip to my library, then I right clicked the MC in the library and clicked Properties and then named it 'blueBox' and created an Actionscript linkage with the class name as 'blueBox' and base as 'flash.display.MovieClip'. I added this movieclip to the stage like so:

var myText:TextField = new TextField();
var myFormat:TextFormat = new TextFormat();

myFormat.size = 15;
myFormat.color = 0xFFFFFF;
myFormat.align = TextFormatAlign.CENTER;
myText.defaultTextFormat = myFormat;
myText.wordWrap = true;

var blueBoxOne:blueBox = new blueBox();
blueBoxOne.width = 400;
blueBoxOne.addChild(myText);


blueBoxOne.x = 400;
blueBoxOne.y = 40;
myText.x = 0;

addChild(blueBoxOne);

Now, what is myText's x position relative to? It appears as if it is a few pixels to the right of the middle of blueBoxOne. How do I make the center of the text be in the center of the blueBoxOne MovieClip?

1

1 Answers

0
votes

The position of a child display object is always relative to its parent. Your TextField shows the text centered but its width is too small - to center the text inside the parent, set its width equal to the parent:

myText.width =  blueBoxOne.width;

This is because you never set the width of the TextField and the default width (100px) is just too small for your box.