利用 BitmapData 类和 Bitmap 类打造像素点渐现的效果, 纯AS代码. 不错. 请看效果, 如果想重看效果, 就刷新本页一次:
源文件: 压缩包下载
package {
import flash.display.MovieClip;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.display.Loader;
import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;
import flash.geom.Matrix;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.geom.Rectangle;
import flash.geom.Point;
public class DisplayList extends MovieClip {
private var _bitmapData:BitmapData;
private var _temporaryBitmapData:BitmapData;
private var _loader:Loader;
private var _timer:Timer;
private var _randomValue:uint;
public function DisplayList() {
var bitmapData:BitmapData = new BitmapData(250, 200, true, 0xFFFFFF);
var bitmap:Bitmap = new Bitmap(bitmapData);
addChild(bitmap);
_bitmapData = bitmapData;
_loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoad);
var request:URLRequest = new URLRequest("http://www.rightactionscript.com/samplefiles/image2.jpg");
_loader.load(request);
_temporaryBitmapData = new BitmapData(250, 200, true, 0xFFFFFF);
}
private function onLoad(event:Event):void{
_temporaryBitmapData.draw(_loader, new Matrix(.5, 0, 0, .5));
_timer = new Timer(50, 50);
_timer.addEventListener(TimerEvent.TIMER, onTimer);
_timer.start();
_randomValue = 0;
}
private function onTimer(event:TimerEvent):void{
_randomValue = _bitmapData.pixelDissolve(_temporaryBitmapData, new Rectangle(0, 0, 250, 200), new Point(0, 0), _randomValue, 250 * 200 / 50);
}
}
}