# Invalid BitmapData Error #2015

**URL:** https://forum.kirupa.com/t/invalid-bitmapdata-error-2015/308992
**Category:** Uncategorized
**Created:** [May 4, 2010, 6:12pm UTC](https://forum.kirupa.com/t/invalid-bitmapdata-error-2015/308992 "2010-05-04T18:12:52Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Tony8534875](https://avatars.discourse-cdn.com/v4/letter/t/ed8c4c/32.png) [@Tony8534875](https://forum.kirupa.com/u/Tony8534875)
#### Post date: [May 4, 2010, 6:12pm UTC](https://forum.kirupa.com/t/invalid-bitmapdata-error-2015/308992/1 "2010-05-04T18:12:52Z")

</div>

I’m getting an Invalid BitmapData Error #2015 at flash.display::BitmapData$iinit() that points to the line of code below where a BitmapData object is created. I am using this function to create only a few hundred Item objects, each of which is only 166 px by 96 px in size so I don’t believe that the problem has to do with running out of memory. I also used system.totalMemory to trace memory consumption but it showed that only a few tens of megabytes were used when the error occurred. I have tried setting the BitmapData and Bitmap objects to null because that was a solution I found on another site. That didn’t work. I tried dispose(). The error occurs intermittently, sometimes after running my app a few times and sometimes when I first load it. I am not refreshing my browser over and over in order to run the app. I cannot figure out the exact sequence of events that leads to this error. In earlier versions of my app, I was able to successfully use the exact same function (minus the lines where the BitmapData and Bitmap objects are set to null). I am not an expert at Actionscript, so perhaps I’m doing something wrong. Please help me out. Thanks.

public function cloneItem(item:Item):Item {  
var itemClone:Item = new Item(item.ID, item.name, item.bpCost, item.bcCost, item.quantity);  
var tempBitmap:Bitmap;  
var tempBitmapData:BitmapData;  
var tempSprite:Sprite;

if (item.card != null) {  
itemClone.card = new mcCard();

itemClone.card.txbCardName.text = item.card.txbCardName.text;  
itemClone.card.setCost(item.card.cost);  
itemClone.card.txbSet.text = item.card.txbSet.text;  
itemClone.card.txbRarity.text = item.card.txbRarity.text;  
itemClone.card.txbLevel.text = item.card.txbLevel.text;  
itemClone.card.txbType.text = item.card.txbType.text;

if (itemClone.card.txbType.text.indexOf(‘Unit’) == -1 && itemClone.card.txbType.text.indexOf(‘Hero’) == -1 && itemClone.card.txbType.text.indexOf(‘Leader’) == -1) {  
itemClone.card.hideUnitAttributes();  
} else {  
itemClone.card.txbAttack.text = item.card.txbAttack.text;  
itemClone.card.txbHP.text = item.card.txbHP.text;

if (itemClone.card.txbType.text.indexOf(‘Leader’) == -1) {  
itemClone.card.lblMP.visible = false;  
itemClone.card.txbMP.visible = false;  
} else {  
itemClone.card.lblAttack.visible = false;  
itemClone.card.txbAttack.visible = false;  
itemClone.card.mcSword.visible = false;

itemClone.card.lblHP.x = itemClone.card.lblAttack.x;  
itemClone.card.txbHP.x = itemClone.card.txbAttack.x;  
itemClone.card.mcHeart.x = 0;

itemClone.card.txbMP.text = item.card.txbMP.text;  
}  
}

itemClone.card.txbRules.text = item.card.txbRules.text;

tempBitmapData = new BitmapData(166, 96);  
tempBitmapData.draw(item.card.mcImage);  
tempBitmap = new Bitmap(tempBitmapData);  
[//tempBitmap.cacheAsBitmap](https://tempBitmap.cacheAsBitmap) = false;  
[//tempBitmap.smoothing](https://tempBitmap.smoothing) = true;  
tempSprite = new Sprite();  
tempSprite.addChild(tempBitmap);  
itemClone.card.mcImage.addChild(tempSprite);

[//tempBitmapData.dispose](https://tempBitmapData.dispose)();

tempBitmapData = null;  
tempBitmap = null;

itemClone.card.buttonMode = true;  
itemClone.card.mouseChildren = false;  
itemClone.card.tabEnabled = false;  
}

return itemClone;  
}
