简体   繁体   中英

How can I set an image as background for a movie clip in flash/as3?

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!

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM