Apache – FLEX: Repeating a background on component

apache-flex

I want to use small images and repeat them as backgrounds for components in Flex. Flex components currently have a backgroundImage property that allows you to pass a URL or a class to be used as the background. There is also a property called backgroundSize that you can set as "auto" which makes it the size of the image, or 100% which makes it stretch to the size of the component. No repeat options. So I downloaded a class that extends the SWFLoader class called RepeatingImage from here: http://renaun.com/flex2/posts/repeatingimage/index.html This class allows you to set a source and it repeats it. I extended this class to have a default source of the image I want to use as a background image, I set the new class as the backgroundImage. and set backgroundSize to 100%. I thought this was a very clever solution while I was doing it, only to find out that it doesn't work, There is no background image set when I do this?

So maybe there is something I need to change to make my method work or maybe someone has a different method, either way I would like to be able to set a repeating background image on a component?

Thanks!

Best Answer

This site recommends using Degrafa. Background Image Repeat

It seems that most solutions that do this manually involve overloading the updateDisplayList() with the following code: Taken from Source

override protected function updateDisplayList(w:Number,h:Number):void
{
    super.updateDisplayList( w, h );

    graphics.clear();               
    graphics.beginBitmapFill( backgroundBitmapData );          
    graphics.drawRect( 0, 0, w, h );  

    ...
}
Related Topic