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.

May 30, 2008

Bitmapdata larger than 2880 pixel

Filed under: Flash AS3 — flas3 @ 5:19 am
Tags: , , , , , , , ,

The width and height parameters specify the size of the bitmap; the maximum value of both is 2880 pixels. Then how to create bitmapdata larger than the maximum specified size?

There are some tricks to snap a bitmap greater than 2880 pixels. One of the trick is this…

1. Load an empty white or black image of desired pixel size [say it would be around 3000x3000 pixels]

2. Clone its bitmapdata.

var bmpDtaClone:BitmapData = bmp.bitmapData.clone();

3. Now you free to draw anything on this bitmap data and flash would have no objection on it.

bmp.floodFill(0, 0, 0xFFFFFFFF);
bmpDtaClone.draw(this, this.transform.matrix, null, null, null, true);

Caution: Dont forget to dispose the bitmapdata as bitmapdata does not dispose itself. It could choke the memory tunnels.

Try this!

Blog at WordPress.com.