# Reads package but doesn't add child

**URL:** <https://forum.kirupa.com/t/reads-package-but-doesnt-add-child/264584>\
**Category:** flash\
**Created:** [June 27, 2008, 2:38pm UTC](https://forum.kirupa.com/t/reads-package-but-doesnt-add-child/264584 "2008-06-27T14:38:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![partimer](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@partimer](https://forum.kirupa.com/u/partimer)\
**Post date:** [June 27, 2008, 2:38pm UTC](https://forum.kirupa.com/t/reads-package-but-doesnt-add-child/264584/1 "2008-06-27T14:38:48Z")

</div>

Hi all,

I got some help here from Charleh here earlier but am syuck on another problem and have no idea why?

I have my main FLA with a doc class of Main. The following imports some nav sprites from the Main class and does load the MainText class (traces the ‘done’ at the end of it) but doesn’t actually add the text - any help here would be much appreciated!

(happy weekend to you all!)

Main.as:

[COLOR=darkred][SIZE=1]package {  
import flash.display.Sprite;  
import flash.display.MovieClip;

public class Main extends Sprite {

public function Main():void {  
doBuild();  
var mainText = new MainText();  
}

public function doBuild():void {

var Navigation2:Sprite=new rightPanel2();  
addChild(Navigation2);

var Navigation:Sprite=new rightPanel();  
addChild(Navigation);

}  
}  
}[/SIZE][/COLOR]

The MainText.as:

[COLOR=darkred][SIZE=1]package {  
import flash.display.MovieClip;  
import flash.text.\*;

public class MainText extends MovieClip {  
public function MainText() {

var css:StyleSheet = new StyleSheet();

var body:Object = new Object();  
body.fontFamily = “Verdana”;  
body.textIndent = 0;

var heading:Object = new Object();  
heading.fontSize = 16;  
heading.textIndent = 0;  
heading.leading = 10;  
heading.letterSpacing = 0;  
heading.fontWeight = “bold”;  
heading.color = “#333333”;  
heading.textAlign = “center”;

var byline:Object = new Object();  
byline.fontSize = 14;  
byline.leading = 20;  
byline.fontStyle = “italic”;  
byline.textAlign = “right”;

css.setStyle(".heading", heading);  
css.setStyle(".byline", byline);  
css.setStyle(“body”, body);

var txtFld:TextField = new TextField();  
txtFld.x =830;  
txtFld.y =10;  
txtFld.width = 100;  
txtFld.multiline = true;  
txtFld.wordWrap = true;  
txtFld.selectable = false;  
txtFld.embedFonts = true;  
txtFld.autoSize = TextFieldAutoSize.LEFT;  
txtFld.styleSheet = css;  
txtFld.htmlText = “\<body\>”;  
txtFld.htmlText += “\<span class=‘heading’\>Text\</span\>”;  
txtFld.htmlText += “\</body\>”;  
addChild(txtFld);

trace(“done”);

}  
}  
}[/SIZE][/COLOR]

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [June 27, 2008, 2:42pm UTC](https://forum.kirupa.com/t/reads-package-but-doesnt-add-child/264584/2 "2008-06-27T14:42:28Z")

</div>

you have to addchild everything you want to show up, in a sense.

so;

var mainText = new MainText();  
addChild(mainText);

---

<div class="post-metadata">

**Author:** ![partimer](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@partimer](https://forum.kirupa.com/u/partimer)\
**Post date:** [June 27, 2008, 2:52pm UTC](https://forum.kirupa.com/t/reads-package-but-doesnt-add-child/264584/3 "2008-06-27T14:52:44Z")

</div>

Thanks sekasi: one question if I may?

You mean adding this on the Main.as file? - just that I’ve tried that and it still doesn’t appear (still no error tho and the ‘done’ gets traced):

Main.as:

[COLOR=“DarkRed”]package {  
import flash.display.Sprite;  
import flash.display.MovieClip;

public class Main extends Sprite {

public function Main():void {  
doBuild();  
var mainText = new MainText();  
**addChild(mainText);**  
}

public function doBuild():void {

var Navigation2:Sprite=new rightPanel2();  
addChild(Navigation2);

var Navigation:Sprite=new rightPanel();  
addChild(Navigation);

}  
}  
}[/COLOR]
