Skip to main content
October 31, 2013
Question

Unable to turn off my webcam using AS3

  • October 31, 2013
  • 1 reply
  • 2096 views

To turn off my webcam (light) I'm using

onScrenVideo.attachCamera(null)

where onScreenVideo is a Video object.

However, this just doesn't seem to work. Even after this line executes, the webcam light remains ON.

I have scoured the Internet for a solution to this problem and everyone seems to be unanimous that this is the only way to turn the webcam off, however, this just doesn't seem to be working for me.

Can anyone help?

Thanks

This topic has been closed for replies.

1 reply

Inspiring
October 31, 2013

If you have a netstream object, call attachCamera(null) on that.

Otherwise, directly on a video container on stage should work. As a test, I just added a video object to the library, dragged it on stage, gave it an instance name of vid, and then added this script:

 

var cam:Camera = Camera.getCamera(); 

vid.attachCamera(cam);

aButton.addEventListener(MouseEvent.CLICK, detach);

function detach(e:MouseEvent):void

{

          vid.attachCamera(null);

}

And it works fine - light on cam goes off.

November 1, 2013

I have done something similar.  

testCurrCam = Camera.getCamera();

onScreenVideo = new Video(240, 180);

onScreenVideo.smoothing = true;

onScreenVideo.x = 0;

onScreenVideo.y = 0;

addChild(onScreenVideo);

testCurrCam.setQuality(0, 70);

testCurrCam.setMode(640, 480, 10);

onScreenVideo.attachCamera(testCurrCam);

And to stop the cam the following function is called. 

private function stopCam(): void {  

     if (contains(onScreenVideo)) {       

          onScreenVideo.attachCamera(null);

          this.removeChild(onScreenVideo);

          onScreenVideo = null;

          testCurrCam = null;

       }   else

             return;

}

The variable declarations are done elsewhere. This doesn't seem to work. The video is displayed all right, but when a button is clicked, and stopCam is called, the light doesn't go off. The problem exists on Windows, Mac and Linux.  The functions are called from JS using ExternalInterface.