package
{
import flash.display.*;
import flash.events.*;
import flash.geom.*;
public class AS3Threshold extends MovieClip
{
private var value:Number;
private var _bmpData:BitmapData;
private var _bmpDataPerlin:BitmapData;
private var rect:Rectangle;
private var pt:Point;
public function AS3Threshold():void
{
}
public function startEffect(_clip:MovieClip):Bitmap
{
// capture the _clip as a bitmap
_bmpData = new BitmapData(_clip.width,_clip.height,true);
_bmpData.draw(_clip);
_bmpDataPerlin = new BitmapData(_clip.width,_clip.height,false);
_bmpDataPerlin.perlinNoise(50,50,2,1,true,true,7,true);
value = 1;
addEventListener(Event.ENTER_FRAME, applyEffect);
var _bmp:Bitmap = new Bitmap(_bmpData);
rect = new Rectangle(0,0,_bmpDataPerlin.width,_bmpDataPerlin.height);
pt = new Point(0,0);
return _bmp;
}
public function applyEffect(e:Event):void
{
value -= .01;
if (value < .01) {
removeEventListener(Event.ENTER_FRAME,applyEffect);
} else {
//var threshold:uint = 0x7F000000;
var threshold:uint = 0xFFFFFF;
var color:uint = 0x00FF00;
var maskColor:uint = 0xffffff;
_bmpData.threshold(_bmpDataPerlin, rect, pt, ">=", (value *threshold), color, maskColor, false);
}
}
}
}
// Usage Example
//
// import AS3Threshold;
// var as3Threshold:AS3Threshold = new AS3Threshold();
// myMovieClip.gotoAndStop(1);
// var bmp:Bitmap = as3Threshold.startEffect(myMovieClip);
// addChild(bmp);
// myMovieClip.gotoAndStop(2);