Reputation: 4876
I am working on a mini-app in Adobe Flash/ActionScript 3 in which I have to change the color of some objects on the scene by clicking a set of buttons. For the same objects I have to set some patterns (using images).
I can handle the change of the color, but I do not know how to put an image as background.
How can it be done?
Thank you!
Upvotes: 1
Views: 4688
Reputation: 12420
You could use Graphics
to draw the image.
// Draw the background
var shape:Shape = new Shape();
shape.graphics.beginBitmapFill(myBitmapData);
shape.drawRect(0, 0, myBitmapData.width, myBitmapData.height);
shape.endFill();
// Reference for later
var background:DisplayObject = shape;
You could also use Bitmap
to display the image.
// Display the image
var bitmap:Bitmap = new Bitmap(myBitmapData);
// Reference for later
var background:DisplayObject = bitmap;
Now you can add this background to your object.
// Add the background at the lowest depth level
myObject.addChildAt(background, 0);
Upvotes: 3