好的,最简单的方法是这样的:
static const WIDTH:int=1280;
static const HEIGHT:int=720;
static const WH:int=WIDTH*HEIGHT;
static const FRAMES:int=120; // 2 seconds * 60 frames. Adjust as needed
static var VF:Vector.<int>; // primary randomizer
static var BD:BitmapData; // displayed object
static var curFrame:int; // current frame
static var BDRect:Rectangle;
function init():void {
// does various inits
if (!VF) VF=new Vector.<int>(WH,true); // fixed length to optimize memory usage and performance
if (!BD) BD=new BitmapData(WIDTH,HEIGHT,false,0); // non-transparent bitmap
BDRect=BD.rect;
BD.fillRect(BDRect,0); // for transparent BD, fill with 0xff000000
curFrame=-1;
for (var i:int=0;i<WH;i++) VF[i]=Math.floor(Math.random()*FRAMES); // which frame will have the corresponding pixel lit white
}
function onEnterFrame(e:Event):void {
curFrame++;
BD.lock();
BD.fillRect(BDRect,0);
if ((curFrame>=0)&&(curFrame<FRAMES)) {
// we have a blinking frame
var cw:int=0;
var ch:int=0;
for (var i:int=0;i<WH;i++) {
if (VF[i]==curFrame) BD.setPixel(cw,ch,0xffffff);
cw++; // next column. These are to cache, not calculate
if (cw==WIDTH) { cw=0; ch++; } // next row
}
} else if (curFrame>FRAMES+20) {
// allow the SWF a brief black period. If not needed, check for >=FRAMES
init();
}
BD.unlock();
}
function Main() {
init();
addChild(new Bitmap(BD));
addEventListener(Event.ENTER_FRAME,onEnterFrame);
}