<iframe align="center" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog336280.html" frameborder="0" width="336" scrolling="no" height="280"></iframe>
用as3调用摄像头,代码如下:
package{
importflash.display.Sprite;
importflash.text.*;
importflash.media.Camera;
importflash.events.StatusEvent;
importflash.events.ActivityEvent;
importflash.media.Video;
publicclassCameraExextendsSprite
{
privatevarlabel:TextField;
privatevarcamera:Camera;
publicfunctionCameraEx()
{
label=addLabel("CameraEx");
camera=Camera.getCamera();
if(camera!=null){
camera.addEventListener(StatusEvent.STATUS,statusHandler);
camera.addEventListener(ActivityEvent.ACTIVITY,activityHandler);
varvideo:Video=newVideo(200,200);
video.attachCamera(camera);
addChild(video);
video.x=20;
video.y=20;
}
else{
label.text="不能使用";
}
}
privatefunctionstatusHandler(evt:StatusEvent):void{
if(camera.muted)label.text="不能使用";
}
privatefunctionactivityHandler(evt:ActivityEvent):void{
if(evt.activating){
label.text="检测开始";
}
else{
label.text="检测停止";
}
}
privatefunctionaddLabel(text:String):TextField{
varlabel:TextField=newTextField();
label.autoSize=TextFieldAutoSize.LEFT;
label.text=text;
addChild(label);
returnlabel;
}
}
}
附件下载:
CameraEx.rar
importflash.display.Sprite;
importflash.text.*;
importflash.media.Camera;
importflash.events.StatusEvent;
importflash.events.ActivityEvent;
importflash.media.Video;
publicclassCameraExextendsSprite
{
privatevarlabel:TextField;
privatevarcamera:Camera;
publicfunctionCameraEx()
{
label=addLabel("CameraEx");
camera=Camera.getCamera();
if(camera!=null){
camera.addEventListener(StatusEvent.STATUS,statusHandler);
camera.addEventListener(ActivityEvent.ACTIVITY,activityHandler);
varvideo:Video=newVideo(200,200);
video.attachCamera(camera);
addChild(video);
video.x=20;
video.y=20;
}
else{
label.text="不能使用";
}
}
privatefunctionstatusHandler(evt:StatusEvent):void{
if(camera.muted)label.text="不能使用";
}
privatefunctionactivityHandler(evt:ActivityEvent):void{
if(evt.activating){
label.text="检测开始";
}
else{
label.text="检测停止";
}
}
privatefunctionaddLabel(text:String):TextField{
varlabel:TextField=newTextField();
label.autoSize=TextFieldAutoSize.LEFT;
label.text=text;
addChild(label);
returnlabel;
}
}
}