topical media & game development
#cmaera-jp.mx
#cmaera-jp.mx
[swf]
flex
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
paddingLeft="0" paddingTop="0" paddingBottom="0" paddingRight="0"
viewSourceURL="@mx-camera-plus.html"
layout="absolute"
initialize="init();">
script
<mx:String id="dispState" />
<mx:Script>
<![CDATA[
import flash.media.Camera;
import flash.filters.BlurFilter;
import flash.filters.GlowFilter;
import flash.filters.ConvolutionFilter;
import flash.geom.ColorTransform;
import flash.display.StageDisplayState;
import mx.managers.SystemManager;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import mx.controls.Alert;
import flash.geom.Rectangle;
import flash.geom.Point;
private var camera:Camera = Camera.getCamera();
private var on:int = 0;
private var conv:int = 0;
private function init() : void {
myVid.attachCamera(camera);
application.addEventListener(KeyboardEvent.KEY_DOWN, onKeyboardEvent);
systemManager.stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullScreenHandler);
dispState = systemManager.stage.displayState;
}
private function onKeyboardEvent(event:KeyboardEvent):void {
Alert.show(event.type + " event was fired " + event.keyCode);
switch(event.keyCode) {
case 65: blur(); break; //B
case 66: color(); break; //C
case 69: toggle(); break; // F
case Keyboard.UP: color(); break;
case Keyboard.DOWN: color(); break;
case Keyboard.LEFT: color(); break;
case Keyboard.RIGHT: color(); break;
default: break;
}
}
private function fullScreenHandler(evt:FullScreenEvent):void {
dispState = systemManager.stage.displayState + " (fullScreen=" + evt.fullScreen.toString() + ")";
if (evt.fullScreen) {
/* Do something specific here if we switched to full screen mode. */
} else {
/* Do something specific here if we switched to normal mode. */
}
}
private function toggle():void {
try {
switch (systemManager.stage.displayState) {
case StageDisplayState.FULL_SCREEN:
systemManager.stage.displayState = StageDisplayState.NORMAL;
break;
default: systemManager.stage.displayState = StageDisplayState.FULL_SCREEN;
break;
}
} catch (err:SecurityError) {
// ignore
}
}
private function stop() : void {
myVid.filters = [];
}
private function blur() : void {
//myVid.filters = [new BlurFilter(5, 5, 3)];
if (on == 0) {
monitor.text = "creative technology";
on = 1;
} else if (on == 1) {
monitor.text = "";
message.text = " クリエイティブテクノロジー / ニューメディア";
on = 2;
} else if (on == 2) {
monitor.text = "";
message.text = "";
subtext.text = "creative technology / new media";
on = 3;
} else if (on == 3) {
monitor.text = "";
message.text = "";
subtext.text = "";
on = 0;
}
}
private function glow() : void {
//myVid.filters = [new GlowFilter(0xff1122)];
var matrix:Array = [ 0,1,0, 1,5,1, 0,1,0 ];
switch (conv) {
case 0:
matrix = [ 0,0,0, 0,2,0, 0,0,0 ];
myVid.filters = [new ConvolutionFilter(3,3,matrix)];
break;
case 1:
matrix = [ -1,-1,-1, -1,8,-1, -1,-1,-1 ];
myVid.filters = [new ConvolutionFilter(3,3,matrix)];
break;
case 2:
matrix = [ -1,-1,-1, -1,5,-1, 1,-1,1 ];
myVid.filters = [new ConvolutionFilter(3,3,matrix)];
break;
case 3:
matrix = [ 1,1,1, 1,8,1, 1,1,1 ];
myVid.filters = [new ConvolutionFilter(3,3,matrix)];
break;
case 4:
matrix = [ -1,-1,-1, -1,4,0, 0,0,0 ];
myVid.filters = [new ConvolutionFilter(3,3,matrix)];
break;
case 5:
matrix = [ 0,0,0, 1,5,-1, -1,-1,-1 ];
myVid.filters = [new ConvolutionFilter(3,3,matrix)];
break;
default:
matrix = [ -2,-1,0, -1,4,1, 0,1,2 ];
myVid.filters = [new ConvolutionFilter(3,3,matrix)];
conv = 0;
break;
}
conv += 1;
}
private function color() : void {
var red:Number = Math.random() * 255;
var green:Number = Math.random() * 255;
var blue:Number = Math.random() * 255;
if (on == 0) {
on = 1; myVid.transform.colorTransform = new ColorTransform(-1, -1, -1, 1, red, green, blue, 0);
} else {
on = 0; myVid.transform.colorTransform = new ColorTransform();
}
}
]]>
</mx:Script>
display
<mx:VideoDisplay top="0" left="0" click="color();" id="myVid" height="100%" width="100%" autoPlay="false"/>
<mx:HBox right="20" bottom="10">
<mx:Button label="blur" click="blur();"/>
<mx:Button label="glow" click="glow();"/>
<mx:Button label="ttop" click="stop();"/>
<mx:Button label="f/v" click="toggle();" cornerRadius="0" />
</mx:HBox>
<mx:Label id="monitor" text="" color="#ffffff" x="50" y="100" fontSize="30" />
<mx:Label id="message" text="" color="#ffffff" x="100" y="175" fontSize="40" />
<mx:Label id="subtext" text="" color="#ffffff" x="150" y="225" fontSize="50" />
</mx:Application>
(C) Æliens
27/08/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.