topical media & game development
sample-flex-camera.mx
sample-flex-camera.mx
[swf]
flex
<?xml version="1.0"?>
camera application
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:ae="*"
paddingLeft="0" paddingTop="0" paddingBottom="0" paddingRight="0"
layout="absolute">
script(s)
<mx:Script>
<![CDATA[
import flash.media.Camera;
private var cameraId:String = "";
private var cameraNo:Number = 0;
private var camera:Camera; // = Camera.getCamera();
inc / dec
private function incno() : void {
setid(cameraNo+1);
}
private function decno() : void {
setid(cameraNo-1);
}
private function setid(n:Number = 0) : void {
cameraNo = n;
if (n > 0) cameraId = "" + (n-1);
else cameraId = "0";
cameralabel.text = "" + n;
}
attach
private function attach(n:Number = 0) : void {
if (n != 0) setid(n);
camera = Camera.getCamera(cameraId);
video.attachCamera(camera);
}
(full) screen toggle(s)
import flash.display.StageDisplayState;
import mx.managers.SystemManager;
public 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
}
}
]]>
</mx:Script>
display
<mx:VideoDisplay id="video" height="100%" width="100%" autoPlay="false"/>
camera control(s)
<mx:HBox top="5" right="3">
<mx:Label color="gray" text="+" click="incno();"/>
<mx:Label color="gray" text="-" click="decno();"/>
<mx:Label id="cameralabel" color="white" text="@"
click="attach(0);"/>
</mx:HBox>
full screen controls
<mx:HBox right="20" bottom="10">
<mx:Button color="gray" borderColor="0" fillAlphas="[0, 0]"
label="[]" click="toggle();"/>
</mx:HBox>
</mx:Application>
(C) Æliens
04/09/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.