/BitmapSheetHandler

Bitmap Sheet Handler for TexturePacker and AS3

BitmapSheetHandler

Utility for Actionscript 3 (Flash, Flex, AIR) and TexturePacker users to handle their image sheets within a project.

Works in web and desktop projects.

Usage

1. Create your (different DPI) sheets and configs in TexturePacker and publish them into your project’s asset folder using Data Format JSON.
2. In your project create a separate Object config for every sheet/json combination:

sheetHandler = new BitmapSheetHandler();
var singleConfig:Object = new Object();
var singlePaths:Object = new Object();
singlePaths['bitmapPath'] = "assets/balls_48.png";
singlePaths['jsonPath'] = "assets/balls_48.json";
singleConfig[BitmapSheetHandler.DPI_SINGLE] = singlePaths;
sheetHandler.importBitmapSheet(singleConfig);
sheetHandler.addEventListener(Event.COMPLETE, onCompleteSingle);

or with multiple sheets to import into the same handler:

multiSheetHandler = new BitmapSheetHandler();
var multiConfig:Object = new Object();	
var multiPaths:Object = new Object();
multiPaths['bitmapPath'] = "assets/balls_48.png";
multiPaths['jsonPath'] = "assets/balls_48.json";
multiConfig[BitmapSheetHandler.DPI_160] = multiPaths;

multiPaths = new Object();
multiPaths['bitmapPath'] = "assets/balls_64.png";
multiPaths['jsonPath'] = "assets/balls_64.json";
multiConfig[BitmapSheetHandler.DPI_240] = multiPaths;

multiPaths = new Object();
multiPaths['bitmapPath'] = "assets/balls_128.png";
multiPaths['jsonPath'] = "assets/balls_128.json";
multiConfig[BitmapSheetHandler.DPI_320] = multiPaths;

multiSheetHandler.importBitmapSheet(multiConfig);
multiSheetHandler.addEventListener(Event.COMPLETE, onCompleteMulti);

3. If you only have one sheet to handle use DPI_SINGLE, else one of the existing DPI_160, DPI_240 or DPI_320 constants
4. You get notified when the last combination has finished importing, where you can then ask the handler for Bitmap or MultiDPIBitmapSource copies:

var bitmap:Bitmap = sheetHandler.getImageSource("basket_ball", false) as Bitmap;
var image:Image = new Image();
image.source = bitmap;
image.x = 50; image.y = 50;
addElement(image);

or with multiple sheets you get back a MultiDPIBitmapSource:

var bitmap:MultiDPIBitmapSource = multiSheetHandler.getImageSource("basket_ball", true) as MultiDPIBitmapSource;
var image:Image = new Image();
image.source = bitmap;
image.x = 50; image.y = 150;
addElement(image);

Useful links