# seamlessBackground Class

**URL:** <https://forum.kirupa.com/t/seamlessbackground-class/217743>\
**Category:** flash\
**Created:** [March 1, 2007, 4:02pm UTC](https://forum.kirupa.com/t/seamlessbackground-class/217743 "2007-03-01T16:02:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jor133d](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jor133d/32/315_2.png) [@jor133d](https://forum.kirupa.com/u/jor133d)\
**Post date:** [March 1, 2007, 4:02pm UTC](https://forum.kirupa.com/t/seamlessbackground-class/217743/1 "2007-03-01T16:02:14Z")

</div>

Hello.

I am using the seamlessBackground class from [pixelfumes.com](http://pixelfumes.com).

I am trying to make a website for myself at [www.glitzphotography.com](http://www.glitzphotography.com) which I use the class.

The background displays the first images then just spreads it across the screen. It only appears correctly after you resize the screen.

Do you know what I mean? Can someone help me modify this script so it works correctly as soon as you load the screen not only after you resize the browser?

Thanks!

```auto
//Seamless Background Class

//Ben Pritchard 2006

//Pixelfumes.com

import flash.display.BitmapData;

class SeamlessBackground{

	var stageWidth:Number;

	var stageHeight:Number;

	var scope:MovieClip;

	var linkageID:String;

	var clipWidth:Number;

	var clipHeight:Number;

	var stageListener:Object;

	var centeredClip:MovieClip = null;

	var tileCount:Number;

	var useBitmap:Boolean;

	

	function SeamlessBackground(s:MovieClip,linkage:String,useBMP:Boolean){

		linkageID = linkage;

		useBitmap = useBMP;

		

		stageListener = new Object();

		stageListener.cRef = this;

		stageListener.onResize = function(){

			this.cRef.updateTiles();

		}

		Stage.addListener(stageListener);

		

		scope = s;

		scope.createEmptyMovieClip("tile_1",1);

		if(useBitmap != true){

			scope["tile_1"].attachMovie(linkageID,"tile",1);

			clipWidth = scope["tile_1"]._width;

			clipHeight = scope["tile_1"]._height;

		}else{

			var bmpd:BitmapData = BitmapData.loadBitmap(linkageID);

			with(scope["tile_1"]){

				beginBitmapFill(bmpd, matrix, repeat, smoothing);

				repeat = true;

				moveTo(0, 0);

				lineTo(0, Stage.height);

				lineTo(Stage.width, Stage.height);

				lineTo(Stage.width, 0);

				lineTo(0, 0);

				endFill();

			}

		}

	}

	

	public function setCenteredClip(mc:MovieClip):Void{

		centeredClip = mc;

		updateTiles();

	}

	

	private function updateTiles():Void{

		if(useBitmap != true){

			destroyTiles();

			

			var fitsX:Number = Math.ceil(Stage.width/clipWidth);

			var fitsY:Number = Math.ceil(Stage.height/clipHeight);

			var colCount:Number = 1;

	

			for(var x:Number=1; x<fitsX*fitsY; x++){

				

				scope.createEmptyMovieClip("tile_"+(x+1),x+1);

				var nClip:MovieClip = scope["tile_"+(x+1)];

				nClip.attachMovie(linkageID,"tile",1);

				var lClip:MovieClip = scope["tile_"+x];

				

				if(colCount+1 > fitsX){

					colCount = 0;

					nClip._x = 0;

					nClip._y = lClip._y + lClip._height;

				}else{

					nClip._x = lClip._x + lClip._width;

					nClip._y = lClip._y;

				}

				colCount++;

			}

					

			tileCount = fitsX*fitsY;

		}else{

			var bmpd:BitmapData = BitmapData.loadBitmap(linkageID);

			with(scope["tile_1"]){

				clear();

				beginBitmapFill(bmpd, matrix, repeat, smoothing);

				moveTo(0, 0);

				lineTo(0, Stage.height);

				lineTo(Stage.width, Stage.height);

				lineTo(Stage.width, 0);

				lineTo(0, 0);

				endFill();

			}

		}

		

		if(centeredClip != null){

			centeredClip._x = (Stage.width/2)-centeredClip._width/2;

			centeredClip._y = (Stage.height/2)-centeredClip._height/2;

		}

	}

	

	public function destroyTiles():Void{

		for(var x:Number=1;x<tileCount;x++){

			scope["tile_"+(x+1)].removeMovieClip();

		}

	}

}

```
