package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Loader; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.geom.Point; import flash.geom.Rectangle; import flash.net.URLRequest; import flash.system.Security; public class BlueBoxTest extends Sprite { private static const ORIGO:Point = new Point(0, 0) private static const RECT:Rectangle = new Rectangle(0,0,400,300) private var background:Loader private var subject:Loader private var subjectData:BitmapData private var contour:Bitmap private var image:BitmapData private var empty:BitmapData private var loader:Loader private var path:String = '' public function BlueBoxTest() { if (Security.sandboxType == 'remote') path=loaderInfo.url.substr(0,loaderInfo.url.lastIndexOf('/')+1) // stage.scaleMode = 'noScale' stage.align = 'TL' addChild(subject = new Loader()) subject.contentLoaderInfo.addEventListener('complete', onSubjectLoadComplete) subject.load(new URLRequest(path + 'subject.jpg')) addChild(background = new Loader()) background.load(new URLRequest(path + 'background.jpg')) background.mask = addChild( contour = new Bitmap( new BitmapData( RECT.width , RECT.height , true ) ) ) background.cacheAsBitmap = background.mask.cacheAsBitmap = true } private function onSubjectLoadComplete(e:Event):void { subjectData = Bitmap( subject.content ).bitmapData stage.addEventListener('mouseMove', onMouseMove) threshold(.5) } private function onMouseMove(e:MouseEvent):void { threshold(e.stageX / RECT.width) } private function threshold(percent:Number):void { contour.bitmapData.threshold(subjectData, RECT, ORIGO, '>', 0xffffff * percent, 0x000000, 0xffffff, true) } } }