简体   繁体   English

如何在flash / as3中将图像设置为影片剪辑的背景?

[英]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. 我正在使用Adobe Flash / ActionScript 3中的迷你应用程序,我必须通过单击一组按钮来更改场景中某些对象的颜色。 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. 您可以使用Graphics绘制图像。

// 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. 您还可以使用Bitmap来显示图像。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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