import flash.display.BitmapData; import flash.display.Bitmap; import flash.geom.Point; import flash.geom.Rectangle; import flash.utils.Timer; import flash.events.TimerEvent; var rndColor: int = Math.random() * 0xffffffff; //随机背景色 var fillColor: int = Math.random() * 0xffffffff; //随机填充色 var bmd: BitmapData = new BitmapData(100, 100, false, rndColor); var bitmap: Bitmap = new Bitmap(bmd); addChild(bitmap); bitmap.scaleX = bitmap.scaleY = 1.5; bitmap.x = stage.stageWidth / 2 - bitmap.width / 2; bitmap.y = stage.stageHeight / 2 - bitmap.height / 2; var tim: Timer = new Timer(20); tim.start(); tim.addEventListener(TimerEvent.TIMER, timerHandler); function timerHandler(event: TimerEvent): void { var randomNum: Number = Math.floor(Math.random() * int.MAX_VALUE); dissolve(randomNum); } function dissolve(randomNum: Number): void { var rect: Rectangle = bmd.rect; var pt: Point = new Point(0, 0); var numberOfPixels: uint = 100; //每次融解100个像素 bmd.pixelDissolve(bmd, rect, pt, randomNum, numberOfPixels, fillColor); var grayRegion: Rectangle = bmd.getColorBoundsRect(0xFFFFFFFF, rndColor, true); if (grayRegion.width == 0 && grayRegion.height == 0) { bmd.dispose(); rndColor = Math.random() * 0xffffffff; fillColor = Math.random() * 0xffffff; bmd = new BitmapData(100, 100, false, rndColor); bitmap.bitmapData = bmd; //tim.stop(); } }