0
votes

I'm starting work on flex using flashbuilder and I was testing cameras. Now I can get a camera to display but when I try using the stop button to stop the camera from capturing, ti doesn't work this is what I tried.

    var video:Video;
    public function startCamera(muteCam:Boolean=false):void{
        video = new Video(); // this will work after the import is done

        var camera:Camera=Camera.getCamera();
        if(muteCam){
        video.attachCamera(camera);

        vidHolder.addChild(video);
        }else{
            video.attachCamera(null);
            if(contains(video))
            vidHolder.removeChild(video);
            //camera=null;

        }


    }

These are my components

<s:Button x="116" y="28" label="Start" click="startCamera(true)"/>
    <s:VideoDisplay id="vidHolder" x="31" y="87" width="200" height="300"
                    />
    <s:Button id="stop" x="208" y="28" label="Stop" click="startCamera(false)"/>
1

1 Answers

1
votes

You are creating a new Video object every single time you call startCamera. So you are trying to remove a video which isn't actually on the stage.

Instead of:

video = new Video();

Use this:

if ( !video ) {
    video = new Video();
}

That will only create the Video object if it has not already been created (!object evaluates the object to see if it is null or a boolean set to false. object == null would evaluate the same way in this case)