/* * Panels.as - Live Chroma Key ActionScript Library * Copyright (c) 2009 Yusuke Kawasaki http://www.kawa.net/ * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * */ package { import flash.display.Sprite; import flash.events.Event; import flash.events.KeyboardEvent; import flash.events.MouseEvent; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; import flash.ui.Keyboard; import org.libspark.LiveChromaKey.LCK_Core; public class Panels extends Sprite { private var chromakey:LCK_Core; public function Panels ():void { // chroma key chromakey = new LCK_Core(); chromakey.init(); var spLive:Sprite = chromakey.getLive(); var spBack:Sprite = chromakey.getBackground(); var spMask:Sprite = chromakey.getMask(); var spFore:Sprite = chromakey.getForeground(); // move panels this.moveSprite( spLive, 0, 0, 0.5, 0.5, 'Live' ); this.moveSprite( spBack, 320, 0, 0.5, 0.5, 'Background' ); this.moveSprite( spMask, 0, 240, 0.5, 0.5, 'Mask' ); this.moveSprite( spFore, 320, 240, 0.5, 0.5, 'Foreground' ); // layers this.addChild( spLive ); this.addChild( spBack ); this.addChild( spMask ); this.addChild( spFore ); // events this.addEventListener( MouseEvent.CLICK, this.onClick ); stage.addEventListener( KeyboardEvent.KEY_DOWN, this.onKeyDown ); } private function moveSprite (sprite:Sprite, x:int, y:int, scaleX:Number = 1.0, scaleY:Number = 1.0, string:String = '' ):void { sprite.x = x; sprite.y = y; sprite.scaleX = scaleX; sprite.scaleY = scaleY; var txtfmt:TextFormat = new TextFormat(); txtfmt.font = 'Arial'; txtfmt.size = 30; txtfmt.color = 0x333333; txtfmt.bold = true; var txtfield:TextField = new TextField(); txtfield.defaultTextFormat = txtfmt; txtfield.multiline = true; txtfield.visible = true; txtfield.text = string; txtfield.x = 10; txtfield.y = 10; txtfield.autoSize = TextFieldAutoSize.LEFT; sprite.addChild( txtfield ); } private function onKeyDown (e:KeyboardEvent):void { if ( e.keyCode == Keyboard.ESCAPE ) { chromakey.runDetector(); } } private function onClick (e:MouseEvent):void { chromakey.runDetector(); } } }