Tiling Background in Actionscript 3.0

He is a quick method fot tiling a background in AS3.0
You ned to have an image in the Library exported to Actionscrip and called image

// set stage proprieties
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

// creating the bitmapdata instance from library
var _tile:BitmapData = new image(0,0);
// container to draw tiles
var _container:Sprite = new Sprite();

// tile background function
function Tile($e:Event):void
{
_container.graphics.clear();
_container.graphics.beginBitmapFill(_tile);
_container.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
_container.graphics.endFill();

}
//add container to stage
addChild(_container);
//events
stage.addEventListener(Event.RESIZE, Tile);
stage.addEventListener(Event.ENTER_FRAME, Tile)
Advertisements

4 thoughts on “Tiling Background in Actionscript 3.0

  1. Pingback: Tiling Background in Actionscript 3.0 « code.zombie | Flash Designers

  2. hey, wanted to find code to do exactly this – but somehow this is not working, i get an error – “1046: Type was not found or was not a compile-time constant: bg_tile.

  3. Make sure you set your image in the Library as ready for actionscript. Go to the image in the library , right click on it, select proprieties, check the Export for Actionscript box.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s