AS3 - Full Screen Tile Class

I’ve made many websites with some sort of tiling texture and finally decided to make a class out of it. Its pretty clean and simple.

Example: http://ronnieswietek.com/hosted/kirupa/tile/

The FLA:


import com.ronnieswietek.GUI.BGTile;
//new Wood(0,0) is reference to a bitmap in your library. My linkage just happens to be Wood
var tile:BGTile = new BGTile(new Wood(0,0));
//You may want to add tile into a movieclip that is on your background layer
addChild(tile);

The class:


package com.ronnieswietek.GUI
{

	import flash.display.*;
	import flash.events.Event;

	public class BGTile extends Sprite
	{
		
		private var reference	:BitmapData;
		private var tile		:Sprite;

		public function BGTile(bitmap:BitmapData)
		{

			addEventListener(Event.ADDED_TO_STAGE, initTile);
			reference 	= bitmap;

		}
		
		private function initTile(e:Event):void
		{
			
			stage.scaleMode 	= StageScaleMode.NO_SCALE;
			stage.align 		= StageAlign.TOP_LEFT;
			removeEventListener(Event.ADDED_TO_STAGE, initTile);
			stage.addEventListener(Event.RESIZE, tileBG);
			tileBG();

		}
		
		private function tileBG(e:Event = null):void
		{

			var oldTile:Sprite 	= tile;
			
			tile 				   = new Sprite();
			tile.graphics.beginBitmapFill(reference);
			tile.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
			tile.graphics.endFill();

			addChild(tile);

			if (oldTile != null && oldTile != tile)
			{
				
				removeChild(oldTile);

			}
			
		}
				
	}
	
}

Hope you guys find it useful!