Reputation: 147
The Question :
I have a dynamically loaded image. It's the background of a site. After 10 seconds, I want to swap out that image with a new image!
The Thoughts :
I had thought this would be a simple enough process.
var BGbmd:BitmapData = new backgroundBitmapData(); // from library
var BG:Bitmap = new Bitmap( BBbmd );
BG.width = stage.stageWidth; //save portrait vs landscape for later...
BG.scaleY = BG.scaleX;
BG.smoothing = true;
addChild( BG );
I figured I'd be able to just change the BGbmd to something else and it would update :
function changeBackground() {
BGbmd = new secondBackgroundBitmapData(); // from Library
}
or something to that extent - but no! nothing changes! it appears I have to remove the child and re-add it which is a pain in the butt because i'd have to keep track of the childIndex…
The Outreach : I'm really hopping that there's some magical function or method that I'm just not able to find that will allow me to easily find swap out bitmapdatas… maybe you'll know!
Thank you all so much! -Joel
Upvotes: 0
Views: 4385
Reputation: 18546
Change the bitmap data inside the Bitmap.
BG.bitmapData = new secondBackgroundBitmapData();
The Bitmap
is the thing on the stage, and it holds onto a reference to the BitmapData
itself -- not the variable its assigned to. So you need to change the Bitmaps
internal state to switch out the images.
Upvotes: 1