Bitmap Backgrounds in Flash 8

Using Flash’s new [color=#0000ff]BitmapData[/color] class and it’s setPixel() method along with the new MovieClip beginBitmapFill() method, it is now possible to create patterned backgrounds directly inside of Flash.

This is just a quick tip, but in a nutshell, this is what is happening: we begin by creating a new 6 pixel by 6 pixel BitmapData and drawing a diagonal line across it. We then create a new MovieClip at an extremely low depth (to be sure it is below everything else that may be on the stage or created dynamically later). Finally, we simply fill the MovieClip with the BitmapData we just created. Easy peasy. I just love Flash.

Here is a quickie copy and paste example:

stop(); 
// 
import flash.display.BitmapData; 
// 
// A dark green color. I like it. 
var myColor:Number = 0x669999; 
// 
// create a new 6x6 non-transparent BitmapData our dark green color 
var bitmapFill = new BitmapData(6, 6, false, myColor); 
// 
function createBackGroundPattern():Void { 
// Draw a black diagonal line across our BitmapData 
bitmapFill.setPixel(0, 5, 0x000000); 
bitmapFill.setPixel(1, 4, 0x000000); 
bitmapFill.setPixel(2, 3, 0x000000); 
bitmapFill.setPixel(3, 2, 0x000000); 
bitmapFill.setPixel(4, 1, 0x000000); 
bitmapFill.setPixel(5, 0, 0x000000); 
// now that we have our pattern we can fill the background with it 
drawBackGround(); 
} 
// 
// Fill the screen with the pattern 
function drawBackGround():Void { 
// Create background movie clip with a ridiculously low depth 
var backGround = _root.createEmptyMovieClip("bg", -99999); 
// Fill the background movie clip with our BitmapData 
with (backGround) { 
	 beginBitmapFill(bitmapFill); 
	 moveTo(0, 0); 
	 lineTo(Stage.width, 0); 
	 lineTo(Stage.width, Stage.height); 
	 lineTo(0, Stage.height); 
	 lineTo(0, 0); 
	 endFill(); 
} 
} 
// 
// Start by creating the pattern. 
createBackGroundPattern();

playing around a little, you can create random background patterns (if for some reason you’d want to) on the fly like this: [color=#800080]http://www.onebyonedesign.com/flash/f8/test5/[/color]