package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.geom.Rectangle; public class test extends Sprite { public function test() { stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; //画一组随机的线条; graphics.lineStyle(0); for(var i:int = 0;i<100;i++) { graphics.lineTo(Math.random()*300,Math.random()*400); } //创建一个不透明位图 var bmpd1:BitmapData = new BitmapData(300,200,false,0xffffff); bmpd1.fillRect(new Rectangle(100,50,100,100),0xff0000); var bmp1:Bitmap = new Bitmap(bmpd1); addChild(bmp1); //创建一个透明位图 var bmpd2:BitmapData = new BitmapData(300,200,true,0x00fffff); bmpd2.fillRect(new Rectangle(100,50,100,100),0x80ff0000); var bmp2:Bitmap = new Bitmap(bmpd2); bmp2.y = 200; addChild(bmp2); } } }
显示效果:上方一个红色的方块,下方为一组随机线条(不断线),透明的红色方块浮在线条上方