0
votes

I am having no luck with trying to create a simple camera in actionscript. I don't want any controls- just a stage asking for permissions, then a livevideo of me in a window. Nothing fancy

Here's what I have so far: (the latest failure...)

     package {

        import flash.display.Sprite;
        import flash.media.*;

        public class FlashCamera extends Sprite
       {
       var cam:FlashCamera = Camera.getCamera(); 
       var vid:Video = new Video(); 
       vid.attachCamera(cam); 
       addChild(vid);


    }

    }

It's throwing this error when I try to compile this: call to a possibly undefined method getCamera through a reference with static type Class

I'm compiling with flex in the windows command line like this:

(path to SDK)/bin/mxmlc Camera.as

Mind you, I am new to actionscript/flash development.

Can someone please explain what I am doing wrong?

2
post the errors that it is throwing when you compile. - fmodos

2 Answers

2
votes

For one thing, you're using classes of the name Camera from two different namespaces without disambiguating between the two. You'll probably also have to import other packages to support API versions of Camera and Video though (flash.media.Camera and flash.media.Video), but I'm not completely convinced this won't be done implicitly, especially not knowing the environment you're using.

Another thing you have to watch out for though, as far as realtime errors go, is when it takes the browser a few seconds to actually get the camera - just keep trying to grab it for at least a few seconds until it returns something other than null.

0
votes

Found somethng that actually works, and will be adapting it for my needs:

  package
        {
            import flash.display.Sprite;
            import flash.events.NetStatusEvent;
            import flash.net.NetConnection;
            import flash.net.NetStream;
            import flash.media.Camera;
            import flash.media.Microphone;
            import flash.media.Video;

        public class FlashVideo extends Sprite
        {
            private var nc:NetConnection;
            private var good:Boolean;
            private var rtmpNow:String;
            private var nsIn:NetStream;
            private var nsOut:NetStream;
            private var cam:Camera;
            private var mic:Microphone;
            private var vidLocal:Video;
            private var vidStream:Video;
            public function FlashVideo()
            {
                trace("Hello testing");
                rtmpNow = "rtmp://localhost/LiveStreams";
                nc=new NetConnection();
                nc.connect(rtmpNow);
                nc.addEventListener(NetStatusEvent.NET_STATUS,checkCon);
                setCam();
                setMic();
                setVideo();
            }
            private function checkCon(e:NetStatusEvent):void
            {
                good = e.info.code == "NetConnection.Connect.Success";
                if (good)
                {
                    nsOut = new NetStream(nc);
                    nsOut.attachAudio(mic);
                    nsOut.attachCamera(cam);
                    nsOut.publish("left","live");
                    nsIn = new NetStream(nc);
                    nsIn.play("right");
                    vidStream.attachNetStream(nsIn);
                }
            }
            private function setCam()
            {
                cam = Camera.getCamera();
                cam.setKeyFrameInterval(9);
                cam.setMode(640,400,30);
                cam.setQuality(0,95);
            }
            private function setMic()
            {
                mic = Microphone.getMicrophone();
                mic.gain = 85;
                mic.rate = 11;
                mic.setSilenceLevel(15,2000);
            }


            private function setVideo()
            {
                vidLocal = new Video(cam.width,cam.height);
                addChild(vidLocal);
                vidLocal.x = 15;
                vidLocal.y = 30;
                vidLocal.attachCamera(cam);
                vidStream = new Video(cam.width,cam.height);
                addChild(vidStream);
                vidStream.x=(vidLocal.x+ cam.width +10);
                vidStream.y = vidLocal.y;
            }
        }
    }