Skip to content

Instantly share code, notes, and snippets.

@rfunduk
Created August 16, 2011 15:20
Show Gist options
  • Save rfunduk/1149345 to your computer and use it in GitHub Desktop.
Save rfunduk/1149345 to your computer and use it in GitHub Desktop.
import flash.display.Graphics;
import flash.display.BitmapData;
import flash.geom.Matrix;
import flash.events.MouseEvent;
[Embed(source='overlay.png')]
private var Overlay:Class;
private var g:Graphics;
private var bmd:BitmapData;
private var m:Matrix;
private var overlay:Boolean = false;
private function drawPlaceHolder():void {
g.clear();
g.lineStyle( 3, 0xDDDDDD, 1 );
g.drawRect( 0, 0, canvas.width, canvas.height );
g.endFill();
g.moveTo( 0, 0 );
g.lineTo( canvas.width, canvas.height );
g.moveTo( canvas.width, 0 );
g.lineTo( 0, canvas.height );
}
public function creationCompleteHandler():void {
g = canvas.graphics;
drawPlaceHolder();
bmd = (new Overlay()).bitmapData;
m = new Matrix();
m.translate( ( canvas.width - bmd.width ) >> 1,
( canvas.height - bmd.height ) >> 1 );
canvas.addEventListener( MouseEvent.MOUSE_MOVE,
function( e:MouseEvent ):void {
if( overlay ) { return; } overlay = true;
g.lineStyle( 0, 0, 0 );
g.beginBitmapFill( bmd, m, false, true );
g.drawRect( 0, 0, canvas.width, canvas.height );
g.endFill();
} );
canvas.addEventListener( MouseEvent.ROLL_OUT,
function( e:MouseEvent ):void {
overlay = false;
drawPlaceHolder();
} );
}
import flash.display.Graphics;
import flash.display.BitmapData;
import flash.display.Shape;
import flash.geom.Matrix;
import flash.events.MouseEvent;
[Embed(source='overlay.png')]
private var Overlay:Class;
private var m:Matrix = new Matrix();
private var s:Shape = new Shape();
private var g:Graphics = s.graphics;
private var bmd:BitmapData = new Overlay().bitmapData;
public function creationCompleteHandler( event:Event ):void {
m.translate( ( image.width - bmd.width ) >> 1,
( image.height - bmd.height ) >> 1 );
g.beginBitmapFill( bmd, m, false, true );
g.drawRect( 0, 0, image.width, image.height );
g.endFill();
image.addEventListener( MouseEvent.MOUSE_MOVE,
function( e:MouseEvent ):void {
if( !image.contains( s ) ) { image.addChild( s ); }
} );
image.addEventListener( MouseEvent.ROLL_OUT,
function( e:MouseEvent ):void {
if( image.contains( s ) ) { image.removeChild( s ); }
} );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment