How can I add a background image?

Hello,

I am start learning Box2D (Box2DFlashAS3_2.0.1) with Flash CS3 for about two weeks. I am sorry that if this is a stupid question.

I wonder how can I add a background image (e.g. bg.png). I tried to add bg.png directly on the stage. I also tried to create a new sprite, and add bg.png to the new sprite in the AS file. However, the bg.png is always on the top.

Please provide a guideline how to do that. I would be much appreciated if a sample file is available.

Thanks and best regards

Alex
Code:
addChildAt(yourSprite, 0)


either that, or add it before you add other things =) This is really a basic AS3 thing, and not related to box2d, i think the official statement is that you keep questions here box2d related - since there are alot of forums related to flash where you can get the basics sorted out (kirupa.com, flashkit.com). No offence, i could be wrong.
Hello,

Thanks for your help.

Yes, I did use addChildAt(yourSprite, 0) to add the image to the new created sprite at the end of the code. Here's my code:

Code:
// Create a new Sprite
var textContainer:Sprite = new Sprite();
         
// Set the location of the new Sprite
textContainer.x = 200;
textContainer.y = 200;

// Create a new TextField
// Add text to the TextField         
var myText_txt:TextField = new TextField();
myText_txt.text = "Hello Physics World";
         
// Add the new textField to the new Sprite (textContainer)
textContainer.addChild(myText_txt);
            
// Add the new Sprite (textContainer) to the stage
addChildAt(textContainer, 0);


However the new sprite is always on the top. I did use addChildAt for some of my exercises before. They all works in normal flash files. I don't know why the addChildAt do not work in the Box2D world.

Best regards

Alex
Then try adding the sprites from the body definitions to a sprite that is ontop.

First
Code:
var textContainer:Sprite = new Sprite();
var bodyContainer:Sprite = new Sprite();
addChild(textContainer);
addChild(bodyContainer);


Then when creating bodies
Code:
bodyContainer.addChild(bodyDef.userData)

Original thread: https://box2d.org/forum/viewtopic.php?t=1396