flash呼叫攝像頭彈出設定框監聽

洪岐發表於2011-11-09

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="horizontal"
        verticalAlign="middle"
        backgroundColor="white">
 
    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.utils.StringUtil;
 
            private function videoDisplay_creationComplete():void {
                var camera:Camera = Camera.getCamera();
                if (camera) {
                    videoDisplay.attachCamera(camera);
                    camera.addEventListener(ActivityEvent.ACTIVITY, camera_activity);
                    camera.addEventListener(StatusEvent.STATUS, camera_status);
                } else {
                    Alert.show("You don't seem to have a camera.");
                }
            }
 
            private function camera_activity(evt:ActivityEvent):void {
                var str:String = "[{0}] activating:{1}\n";
                textArea.text += StringUtil.substitute(str,
                                    evt.type,
                                    evt.activating);
            }
 
            private function camera_status(evt:StatusEvent):void {
                var str:String = "[{0}] code:'{1}', level:'{2}'\n";
                textArea.text += StringUtil.substitute(str,
                                    evt.type,
                                    evt.code,
                                    evt.level);
                switch (evt.code) {
                    case "Camera.Muted":
                        Alert.show("User denied access to camera.");
                        break;
                    case "Camera.Unmuted":
                        Alert.show("User allowed access to camera.");
                        break;
                }
            }
        ]]>
    </mx:Script>
 
    <mx:VideoDisplay id="videoDisplay"
            creationComplete="videoDisplay_creationComplete();"
            width="160"
            height="120" />
 
    <mx:TextArea id="textArea"
            editable="false"
            width="100%"
            height="{videoDisplay.height}"
            wordWrap="false"
            verticalScrollPolicy="on" />
 
</mx:Application>


相關文章