Flash AS3

June 23, 2008

Bitmapdata example larger than 2880 px.

Filed under: Flash AS3 — flas3 @ 7:18 am
Tags: , , , , , , , , ,

Here is a simple example if bitmapdata larger than 2880 px. This is response of my earlier post.

How to use this code…

1. Create an empty folder say bmpTest.
2. Create another folder named imgs inside bmpTest and put tileImg.jpg and canvas.jpg into it.
3. Create an FLA that supports AS3 and create a scrollpane onto the stage. Name it scrPane. Make sure
that dimension of fla would be 800×600 and scrollpane would be 750×530.
4. Create an AS3 class named Main and paste the code below.

////////////////////Code/////////////////////////////

package
{
import flash.display.BitmapData;
import flash.display.MovieClip;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.display.Bitmap;
import flash.geom.Matrix;
import flash.events.*;
public class Main extends MovieClip
{
private var bmpCanvas:BitmapData;
private var bmpTile:BitmapData;
//Constructor
function Main()
{
initialize();
}

private function initialize():void
{
loadTile();
loadCanvas();
}

//Load tile image…
private function loadTile():void
{
var ldrTile:Loader = new Loader();
ldrTile.contentLoaderInfo.addEventListener(Event.COMPLETE, clbTileLoadComplete);
var urlTile:String = “imgs/tileImg.jpg”;
var urlReqTile:URLRequest = new URLRequest(urlTile);
ldrTile.load(urlReqTile);
}
private function clbTileLoadComplete(event:Event):void
{
var tmpBmpTile:Bitmap = event.target.content as Bitmap;
//Store as bitmapdata.
bmpTile = tmpBmpTile.bitmapData.clone();
}

//Load canvas white image
private function loadCanvas():void
{
var ldr:Loader = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, clbCanvasComplete);
var url:String = “imgs/canvas.jpg”;
var urlReq:URLRequest = new URLRequest(url);
ldr.load(urlReq);
}
private function clbCanvasComplete(event:Event):void
{
var tmpBmp:Bitmap = event.target.content as Bitmap;
//Store as bitmapdata
bmpCanvas = tmpBmp.bitmapData.clone();
showTiledImgInPane();
}

private function showTiledImgInPane():void
{
var bmpPane:Bitmap = new Bitmap(bmpCanvas);

//Create tile.
makeTile();

//Show in pane.
scrPane.source = bmpPane;
scrPane.refreshPane();
}

//Tile image. Keep in mind that the tiled images’ dimension is more than the canvas. I simply mean to say  that Tiles will cover complete canvas
//of dimension 3357×3000 px.
private function makeTile():void
{
var wd:uint = bmpTile.width;
var ht:uint = bmpTile.height;
var nTopMargin:Number = 30;
var nLeftMargin:Number = 30;
var nVPitch:Number = 5;
var nHPitch:Number = 5;
for(var i:Number = 0; i < 12; i++)
{
for(var j:Number = 0; j < 10; j++)
{
var mat:Matrix = new Matrix();
var nX:Number = (i * wd) + nLeftMargin;
var nY:Number = (j * ht) + nTopMargin;
if (j != 0)
{
nY = nY + (nVPitch * j);
}
if(i != 0)
{
nX = nX + (nHPitch * i);
}
mat.translate(nX, nY);
bmpCanvas.draw(bmpTile, mat);

mat = null;
nX = 0;
nY = 0;
}
}
}
}
}

////////////////END CODE////////////////////////////

Thanks.

June 2, 2008

Terrorist nature

Filed under: General — flas3 @ 12:29 pm
Tags: ,

Blog at WordPress.com.