Hello. I’m trying to set up a Spritesheet in AS2 with BitmapData but it’s really hard to do. I HAVE to use AS2 for this project so I have no other choice. Can anyone please help me make this code work?
The purpose is to retrieve an image from a website, then split it into however many sections there are, then put each section into a separate movie clip. This has proven to be a hassle in AS2 whereas in AS3 I could have done it in 5 minutes and I am incredibly frustrated as a result.
I’m not trying to get the image properly aligned (that isn’t even the image I want to use. It’s just one for testing.) I’m just trying to get the movieclips containing each sprite to actually work and show up. This is what I have so far.
import flash.display.BitmapData;
import flash.geom.Point;
import flash.geom.Rectangle;
var whatever = new MovieClipLoader();
var mcTar = createEmptyMovieClip("mcTar",this.getNextHighestDepth());
whatever.loadClip("http://spritesheetmaker.com/examples/Ex5.png",mcTar);
var cBmpData:BitmapData;
var spriteColumns:Number = 3
var maxsprites:Number = 9;
mcTar._alpha = 0;//Hide the original spritesheet
whatever.onLoadComplete = function(){
cBmpData = new BitmapData(1024,2048,true,0x00000000);
cBmpData.draw(mcTar);
var cPoint:Point = new Point(0,0);
var cRect:Rectangle = new Rectangle(0,0,35,35);
for(var spriteCount:Number = 0; spriteCount<maxsprites; spriteCount++){
var newMC:MovieClip =_root.createEmptyMovieClip("mcsprite"+spriteCount,_root.getNextHighestDepth());
var newsprite:BitmapData = new BitmapData(35,35,true,0xFF000000);
cRect.x = spriteCount % spriteColumns * 35;
cRect.y = Math.floor(spriteCount/spriteColumns) * 35;
newsprite.copyPixels(cBmpData,cRect,cPoint);
newMC.attachBitmap(newsprite);
//text field to help test.
var tx =newMC.createTextField("lol"+spriteCount,newMC.getNextHighestDepth(),spriteCount % spriteColumns * 35,Math.floor(spriteCount/spriteColumns) * 80,40,40);
tx.text = spriteCount;
newMC.x = spriteCount*30;
newMC.y = Math.floor(spriteCount/spriteColumns) * 80
_root["mcsprite"+spriteCount] = newMC;
}
}
Any help in understanding how AS2 works would be greatly appreciated as well.