MXML/AS error in Camera.get()

i am new to flex/AS programming In the below code what is this error and how to resolve it

     <?xml version="1.0" encoding="utf-8"?>
     <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">


     <mx:Script>
             <![CDATA[
             import mx.controls.Button;
             import mx.controls.Alert;
             import flash.media.Camera;

             public function clickhandler(event:Event):void
             {

                var button:Button=event.target as Button;
                if (button.label=='Test camera')
                {
                       mx.controls.Alert.show("Starting camera1");
                       //myCam = Camera.get();
                       //myVid.attachVideo(myCam);
                       if (Camera.names.length > 0) {
                          cam = Camera.getCamera();
                          if (cam != null) {
                             try
                             {
                                cam.setMode(160,120,8,false); // error here
                                participantVideo.attachCamera(cam);
                                psPublish.attachCamera(cam);
                             }
                             catch(err:Error)
                             {
                                Alert.show("Cannot connect camera");
                             }
                          }
                       }

                ]]>

             </mx:Script>
            <mx:Button id="button1" label="Test camera" width="100" click="clickhandler(event)" />

        </mx:Application>




     /home/tom/programs/flex/camera.mxml(19):  Error: Access of undefined property myCam.

        cam = Camera.getCamera();

Answers


Your code is confusing... you show an error related to myCam, but myCam is commented out!

Let's assume that the error has to do with the cam variable. Have you defined cam?

     private var cam:Camera;

     //or
     var cam:Camera = Camera.getCamera();

Check the example at the bottom of the page for attachCamera()

Following your code...

     private var participantVideo:Video = new Video( 160 , 120 );

     //later in your function
     participantVideo.attachCamera( cam );

Need Your Help

How to implement multi-touch in an android game that uses a main game panel surface view and a main thread

android 2d game-engine multi-touch

I started learning android programming a couple of weeks ago. I am a beginner so I followed this tutorial on making a simple 2D game engine:

How to restart java web start application programatically

java deployment jnlp java-web-start auto-update

I am trying to achieve the automatic update for my java web-start applicaiton. Logic: I am fetching the jnlp file from the server and comparing the timestamp with the current one. if there is diffe...