I needed to add a background graphic to my Flex app and this turned out to be a lot harder than anticipated. While Flex supports CSS it does not support all the attributes that you are used to from HTML nor does it act in the same way.
Specifying a backgroundImage: Embed(source="/assets/bg.png"); will stretch the image, sclae it or do other weird things with it. I don't understand how this is a usable option for a scalable interface.
I am not the only person with this problem so I Googled and found some approaches (this one being quite tricky), of which one seemed to work, at least a little bit :-).
So I tweaked Jeremy's example a bit and came up with this. It uses Jeremy's approach of creating a BitmapData object and Shape and 'painting' into it with a linked image tile.
You can get my sources here and see the demo here (click the button to show the background graphic). I am open to suggestions and comments regarding this approach, it may be resource intensive (maybe not) although my tests showed only a 200KB increase in memory after the graphic was loaded.

#1 by Renaun Erickson on 12/6/06 - 6:55 PM
You can see it here:
http://renaun.com/blog/flex-components/repeatingim...
#2 by Maikel Sibbald on 12/7/06 - 7:19 AM
http://labs.flexcoders.nl/?p=16
#3 by Stefan on 12/7/06 - 10:08 AM
It would be nice to be able to set the image via MXML, maybe via the backgroundImage="" attribute rather than coding it into the class. Just an idea.
cheers
#4 by Renaun Erickson on 12/9/06 - 5:28 AM
I took the code from Maikel and made it so all you have to do is set the borderSkin and backgroundImage styles of the Application component and it works. Check it out here:
http://renaun.com/blog/2006/12/08/165/
Maikel thanks for the code and idea.
#5 by Maikel Sibbald on 12/9/06 - 3:27 PM
I've updated the code. Now you can use it not only the Application, but also Canvas, VBox, HBox, etc...
http://labs.flexcoders.nl/?p=21
#6 by Brad on 12/11/06 - 8:43 PM
#7 by Sharon on 1/5/07 - 9:59 AM
#8 by Mike on 6/21/07 - 12:03 PM
Thanks!
#9 by Varun Shetty on 2/25/08 - 1:40 AM
btw. ne of u guys tried using a 1 pixel line and stretching it as a background?
#10 by Varun Shetty on 2/25/08 - 1:44 AM
backgroundSize*
backgroundImage*
properties in the containers..
#11 by Renaun Erickson on 3/3/08 - 4:13 PM
#12 by Hassan on 1/15/09 - 4:50 AM
I was trying to do a background tiling but Flex did not behave as expected. A small problem like this took me a whole day, and then I run into you program solution. Thank you very much.
Hassan