2 Replies Latest reply: Dec 13, 2012 8:39 AM by jwbell RSS

    Problems using camera - Flash CS4

    jwbell Community Member
      • All updates are installed
      • Please give us more information about your Creative environment:
        • Flash 10.0.2 for CS4
        • Mac OSX v10.7

       

      I am following the ActionScript 3.0 for Adobe Flash CS4 Professional - Classroom in a Book

       

      I am in Lesson 12 where it references accessing the user's camera to display an image caught by the camera.  The intent of the lesson is that once the image is loaded on the screen, filters can be applied to it.  The issue I have is that no image is displayed on my screen.  I have been over the code closely (the completed file that comes pre-loaded ready to go did not work).  I have loaded facetime and I have been to www.testmycam.com and my camera works fine in both instances.  The dialog box comes and asks me to allow or deny.  I of course click ALLOW.  I am at a loss.  The code is below.  Any help would be appreciated.

       

      import fl.ik.*;

      import fl.events.SliderEvent;

      import flash.media.Camera;

      import flash.media.Video;

       

       

      IKManager.trackAllArmatures(false);

      var arm0:IKArmature = IKManager.getArmatureAt(0);

      var rt0:IKJoint = arm0.rootJoint;

      var jt0:IKJoint = rt0.getChildAt(0).getChildAt(0).getChildAt(0);

      var mover0:IKMover = new IKMover(jt0, jt0.position);

       

       

      var fx1:Sound = new Sound();

      fx1.load(new URLRequest("robotArm.mp3"));

      var channel1:SoundChannel = new SoundChannel;                                                                                            

       

       

      var fx2:Sound = new Sound();

      fx2.load(new URLRequest("click.mp3"));

      var channel2:SoundChannel = new SoundChannel;

       

       

      var camera:Camera=Camera.getCamera();

      var video:*;

       

       

      if(camera != null) {

                video = new Video(160, 120);

                video.attachCamera(camera);

                addChild(video);

                trace("camera is ok");

      } else {

                trace("There is no recognized camera connected to your computer.");

                video = new AltVid();

                addChild(video);

      }

       

       

      snapshot_btn.addEventListener(MouseEvent.CLICK, onSnapShot);

       

       

      function onSnapShot(e:MouseEvent):void {

                stage.addEventListener(Event.ENTER_FRAME, moveDown);

                snapshot_btn.visible = false;

                channel1 = fx1.play();

      }

       

       

      function moveDown(e:Event) {

                if(jt0.position.y < 305) {

                          var pt0:Point = new Point(jt0.position.x + 5, jt0.position.y + 5);

                          mover0.moveTo(pt0);

                } else {

                          channel1.stop();

                          channel2 = fx2.play();

                          channel1 = fx1.play();

                             stage.removeEventListener(Event.ENTER_FRAME, moveDown);

                          stage.addEventListener(Event.ENTER_FRAME, moveUp);

                }

      }

       

       

      function moveUp(e:Event):void {

                if(jt0.position.y > 165) {

                          var pt0:Point = new Point(jt0.position.x - 5, jt0.position.y - 5);

                          mover0.moveTo(pt0);

                } else {

                          stage.removeEventListener(Event.ENTER_FRAME, moveUp);

                          snapshot_btn.visible = true;

                          channel1.stop();

                }

      }

       

      Thanks,

      John

        • 1. Re: Problems using camera - Flash CS4
          esdebon Community Member

          Detect a web cam in windows is different to detect a webcam in mac

           

           

           

          function activaWebcam(e:MouseEvent):void{

              //trace("webcam active");

              var index = 0; //for windows - default value  

           

              //Searching index of the webcam in Mac

              for (var i=0 ;i< Camera.names.length;i++) {

                  if ( Camera.names[i] == "USB Video Class Video" ) {

                      index = i;

                  }

              }       

              cam = Camera.getCamera(index);

             video.attachCamera(cam);

          }

          • 2. Re: Problems using camera - Flash CS4
            jwbell Community Member

            esdebon,

             

            Thanks for the quick, great help.  That worked great.  You think they would have mentioned that in the book.  If they did, I overlooked it.  You are great.