Posted 2008/03/10 10:59 by wooyaggo
지금 만드는 캡쳐플그램에 쓸일이 있어서
평소 만들어보고 싶었는데
의외로 이쁘게 만들어졌네요.^^
그릴 영역을 Rectangle 클래스로 설정하고
SelectionLayer.draw( rect ); 로 동작해주시면 됩니다.
SelectionLayer.as 소스보기
package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; import flash.events.TimerEvent; import flash.geom.Rectangle; import flash.utils.Timer;
/** * 선택 영역 효과 레이어. * * @author http://www.as3.kr * @author Wooyaggo ( victim4@gmail.com ) * */ public class SelectionLayer extends Sprite { private var bitmap: Bitmap; private var bitmapData: BitmapData; private var timer: Timer; public function SelectionLayer() { this.bitmapData = new BitmapData( 10, 10, true, 0 ); this.bitmap = new Bitmap( this.bitmapData ); this.addChild( this.bitmap ); this.timer = new Timer( 50 ); this.timer.addEventListener( TimerEvent.TIMER, onTimer ); } private var padding: int = 0; private const GAP: int = 4; public function draw( selection: Rectangle ): void { // reset this.bitmapData.dispose(); this.bitmapData = new BitmapData( selection.width, selection.height, true, 0 ); this.bitmap.bitmapData = this.bitmapData; this.bitmap.x = selection.x; this.bitmap.y = selection.y; this.drawLine(); this.timer.start(); } private function onTimer( e: TimerEvent ): void { this.repeat(); } public function repeat(): void { this.padding++; this.padding %= 2 * GAP; this.drawLine(); } private var lineColor: Number = 0xFF000000; private var lineColor2: Number = 0xFFFFFFFF; private function drawLine(): void { this.bitmapData.fillRect( this.bitmapData.rect, 0 ); var rect: Rectangle; var loop: int; rect = new Rectangle( padding - ( 2 * GAP ), 0, GAP, 1 ); loop = 1 + this.bitmapData.width / ( GAP * 2 ); do { this.bitmapData.fillRect( rect, lineColor ); rect.x += GAP; this.bitmapData.fillRect( rect, lineColor2 ); rect.x += GAP; }while( loop-- ) rect = new Rectangle( 0, padding - ( 2 * GAP ), 1, GAP ); loop = 1 + this.bitmapData.height / ( GAP * 2 ); while( loop-- ) { this.bitmapData.fillRect( rect, lineColor ); rect.y += GAP; this.bitmapData.fillRect( rect, lineColor2 ); rect.y += GAP; } var margin: int; margin = padding - ( this.bitmapData.width % ( 2 * GAP ) ) + 1; rect = new Rectangle( margin - ( 2 * GAP ), this.bitmapData.height - 1, GAP, 1 ); loop = 1 + this.bitmapData.width / ( GAP * 2 ); do { this.bitmapData.fillRect( rect, lineColor ); rect.x += GAP; this.bitmapData.fillRect( rect, lineColor2 ); rect.x += GAP; }while( loop-- ) margin = padding - ( this.bitmapData.height % ( 2 * GAP ) ) + 1; rect = new Rectangle( this.bitmapData.width - 1, margin - ( 2 * GAP ), 1, GAP ); loop = 1 + this.bitmapData.height / ( GAP * 2 ); while( loop-- ) { this.bitmapData.fillRect( rect, lineColor ); rect.y += GAP; this.bitmapData.fillRect( rect, lineColor2 ); rect.y += GAP; } } } } | |
사용예입니다. ( 패키지명 맞춰서 1 frame 에 붙여서 테스트하시면 됩니다. )
import com.display.SelectionLayer
var selection: SelectionLayer = new SelectionLayer(); addChild( this.selection );
var rect: Rectangle = new Rectangle( 0, 0, 200, 200 ); this.selection.draw( rect ); this.selection.x = this.selection.y = 50; | |
[
소스 받기 ]
Tag : 3.0,
as3,
flash,
selection,
선택툴,
플래시
Trackback URL : http://wooyaggo.tistory.com/trackback/117