Flex 2 Application Repeating BackgroundImage Style (updated)
UPDATE: see comments, the skin class works with any UIComponent and checks for many exceptions of different backgroundImage style values. Note backgroundImage values of embedded images only work, embedded SWF’s with symbol names throws an error.
I created a RepeatingImage component last month that works nicely for applying repeating images any where in your Flex application. But most repeating image usages are typical implemented as repeating background image for the whole Application. There is no easy way to apply the background image as a style and have it repeat.
You could use the RepeatingImage component to apply a image class on the Canvas of an Application component, but that might not work for non absolute layout apps. The basic code to repeat a bitmap over an graphic area requires BitmapFill. Stefan Richter modified Jemery Lu’s code to apply a bitmap image to the Application component through AS code in the Script block. This looks a lot like the RepeatingImage in its approach.
Then in Stefan’s comments Maikel Sibbald applied the BitmapFill approach to a borderSkin. This approach makes more sense when you are thinking of just applying a background image on the Application that repeats. The one done side to the code was that it you have to hard code the image source into the custom borderSkin class.
I decided to take that code and modify it so you set the borderSkin and backgroundImage styles on the Application component class to make it work. The trick is the modifications in the custom borderSkin called RepeatedBackground, they RepeatedBackground class locates the backgroundImage style from the parent (which is Application or any other component with borderSkin set to RepeatedBackground) and uses that as the class for the image. It then clears the backgroundImage style on the parent to make sure that that doesn’t get drawn.
See for your self, here is the live example and the source code through context help.
Pingback: Labs@flexcoders » Blog Archive » Repeated background for flex components (Update)