PDA

View Full Version : Replacing a bitmap in a MovieClip



richjamison
March 13th, 2008, 09:13 AM
I have a MovieClip Class called Capsule that gets added to the stage multiple times in a for loop. The Capsule I had pre-designed with a Bitmap inside of it. The Bitmap needs to be replaced with a different Bitmap from the library for each instance of the Capsule placed on the stage.

How can I replace the Bitmap?

Here is the code that I use to add the Capsules. Pretty standard I think:


for (var i:int = 0; i < docCount; i++) {
var myCapsule:Capsule = new Capsule();
myCapsule.name = "Dr. " + String(docsArray[i]);//"myCapsule" + i;

myCapsule.scaleX = .25;
myCapsule.scaleY = .25;

myCapsule.myRads = capsuleAngle;
//myCapsule.mySubjectName = "";
myCapsule.x = carouselCenterX + Math.sin(capsuleAngle) * radiusX;
myCapsule.y = carouselCenterY + Math.cos(capsuleAngle) * radiusY;

allMyCapsulesYpos[i] = myCapsule.y;
allMyCapsulesXpos[i] = myCapsule.x;
var myScale:Number = new Number(myCapsule.y / (carouselCenterY + radiusY));
myCapsule.scaleX = myCapsule.scaleX * myScale;
myCapsule.scaleY = myCapsule.scaleY * myScale;

myCapsule.addEventListener(MouseEvent.MOUSE_OVER, doctorMouseOver);
myCapsule.addEventListener(MouseEvent.MOUSE_OUT, doctorMouseOut);
myCapsule.addEventListener(Event.ENTER_FRAME, rotateCarousel);

allMyCapsules[i] = myCapsule;
myCapsuleContainer.addChild(myCapsule);
capsuleAngle += capsuleAngleIncrement;
}Here's the layers of the Capsule:
Pic is the layer that the Bitmap is on.
http://www.fbnpodcasts.com/TempImages/CapsuleLayers.png

Anyone?

Thanks

richjamison
March 13th, 2008, 12:05 PM
I have a MovieClip Class called Capsule that gets added to the stage multiple times in a for loop. The Capsule I had pre-designed with a Bitmap inside of it. The Bitmap needs to be replaced with a different Bitmap from the library for each instance of the Capsule placed on the stage.

How can I replace the Bitmap?

Here is the code that I use to add the Capsules. Pretty standard I think:


for (var i:int = 0; i < docCount; i++) {
var myCapsule:Capsule = new Capsule();
myCapsule.name = "Dr. " + String(docsArray[i]);//"myCapsule" + i;

myCapsule.scaleX = .25;
myCapsule.scaleY = .25;

myCapsule.myRads = capsuleAngle;
//myCapsule.mySubjectName = "";
myCapsule.x = carouselCenterX + Math.sin(capsuleAngle) * radiusX;
myCapsule.y = carouselCenterY + Math.cos(capsuleAngle) * radiusY;

allMyCapsulesYpos[i] = myCapsule.y;
allMyCapsulesXpos[i] = myCapsule.x;
var myScale:Number = new Number(myCapsule.y / (carouselCenterY + radiusY));
myCapsule.scaleX = myCapsule.scaleX * myScale;
myCapsule.scaleY = myCapsule.scaleY * myScale;

myCapsule.addEventListener(MouseEvent.MOUSE_OVER, doctorMouseOver);
myCapsule.addEventListener(MouseEvent.MOUSE_OUT, doctorMouseOut);
myCapsule.addEventListener(Event.ENTER_FRAME, rotateCarousel);

allMyCapsules[i] = myCapsule;
myCapsuleContainer.addChild(myCapsule);
capsuleAngle += capsuleAngleIncrement;
}Here's the layers of the Capsule:
Pic is the layer that the Bitmap is on.
http://www.fbnpodcasts.com/TempImages/CapsuleLayers.png

Anyone?

Thanks



So after digging around a bit I came up with this.

I went into my Capsule MovieClip and converted the Bitmap to a MovieClip Symbol. I gave it an instance name of "ImageContainer". So now in my for loop I load a Bitmap from the library into the ImageContainer like this.


//path to ImageContainer is myCapsule.ImageContainer
// create instance of Cavazos bitmap data
var doctorImageData:Cavazos = new Cavazos(0, 0);

// create a bitmap instance that references the Cavazos instance
var doctorImageBitmap:Bitmap = new Bitmap(doctorImageData);
doctorImageBitmap.x -= doctorImageBitmap.width * 0.5;
doctorImageBitmap.y -= doctorImageBitmap.height * 0.5;
// add the new bitmap to the display list
myCapsule.ImageContainer.mouseEnabled = false;
myCapsule.ImageContainer.addChild(doctorImageBitma p);Now on to the next hurdle. How to change the Bitmap on each iteration of the for loop. For example every where Cavazos appeared in the previous code would be replaced with Duperier:


//path to ImageContainer is myCapsule.ImageContainer
// create instance of Duperier bitmap data
var doctorImageData:Duperier = new Duperier(0, 0);

// create a bitmap instance that references the Duperier instance
var doctorImageBitmap:Bitmap = new Bitmap(doctorImageData);
doctorImageBitmap.x -= doctorImageBitmap.width * 0.5;
doctorImageBitmap.y -= doctorImageBitmap.height * 0.5;
// add the new bitmap to the display list
myCapsule.ImageContainer.mouseEnabled = false;
myCapsule.ImageContainer.addChild(doctorImageBitma p);Anyone have any ideas on that.