ActionScript3 - Remove bitmap and bitmapData
How to remove the bitmap from the holder and the bitmapData from the Flash Player memory?
var _myThumb:Bitmap;
var _myThumbData:BitmapData;
var bitmap:Bitmap
//
function createThumbs()
{
_myThumbData = new BitmapData(pic.picdefault.width,pic.picdefault.height,false,0xffffff);
//
picthumbs.t1.holder.addChild(createBitmap(_myThumbData));
picthumbs.t2.holder.addChild(createBitmap(_myThumbData));
picthumbs.t3.holder.addChild(createBitmap(_myThumbData));
picthumbs.t4.holde开发者_Python百科r.addChild(createBitmap(_myThumbData));
picthumbs.t5.holder.addChild(createBitmap(_myThumbData));
}
function createBitmap(bmd:BitmapData):Bitmap
{
var bitmap:Bitmap = new Bitmap(bmd);
bitmap.smoothing = true;
setSize(bitmap, bmd.width, bmd.height, 94, 94);
return bitmap;
}
function setSize(target:DisplayObject, contentWidth:Number, contentHeight:Number, targetWidth:Number, targetHeight:Number):void {
var w:Number = targetWidth;
var h:Number = targetHeight;
var containerRatio:Number = targetWidth / targetHeight;
var imageRatio:Number = contentWidth / contentHeight;
if (containerRatio < imageRatio) h = w / imageRatio;
else w = h * imageRatio;
target.width = w;
target.height = h;
target.x = (targetWidth - w) * .5;
target.y = (targetHeight -h) * .5;
}
//
function createThumbnail()
{
_myThumbData.draw(pic.picdefault);
}
Assuming the holder is just an empty MovieClip then you can simply go:
picthumbs.t1.holder.removeChildAt(0);
This will remove the reference to the Bitmap thereby making it eligible for garbage collection. As the BitmapData is only referenced by the Bitmap, and the Bitmap is no longer referenced, then it too will be removed from memory.
Look into BitmapData.dispose().
精彩评论