# AS3 - Full Screen Tile Class

**URL:** <https://forum.kirupa.com/t/as3-full-screen-tile-class/280445>\
**Category:** open source\
**Created:** [January 27, 2009, 7:01pm UTC](https://forum.kirupa.com/t/as3-full-screen-tile-class/280445 "2009-01-27T19:01:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rondog](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rondog/32/2478_2.png) [@rondog](https://forum.kirupa.com/u/rondog)\
**Post date:** [January 27, 2009, 7:01pm UTC](https://forum.kirupa.com/t/as3-full-screen-tile-class/280445/1 "2009-01-27T19:01:17Z")

</div>

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/](http://ronnieswietek.com/hosted/kirupa/tile/)

The FLA:

```auto

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:

```auto

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!
