Avg. Rating 2.0

Problem

If you want to work with a live camera and use the feed, you can use this simple recipe to see the simplistic workings. This project is a great opener for demonstrating Flex, too. You can build this from scratch in about 2-3 minutes.

Solution

Note that this is tooled to work with Flex Builder 3, beta 3. When working with the Camera class, you can pass a named camera to the getCamera method. If you only have one camera, the application will use it by default. If you get nothing, you can right-click (Ctrl-click on Mac) the <mx:VideoDisplay> in the application and chose your device.

Detailed explanation

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
        <![CDATA[
            import flash.media.Camera;
            public var myCamera:Camera;         
            public function startCam():void {
                myCamera = Camera.getCamera();
                myVid.attachCamera(myCamera);
                myVid.autoPlay;
            }
        ]]>
    </mx:Script>   

<mx:Panel x="10" y="10" width="371" height="346" layout="absolute"
        title="Apollo Camera Example" cornerRadius="15" borderColor="#f01032">
    <mx:VideoDisplay id="myVid"
        width="331" height="254"
         x="10" y="10"/>
    <mx:Button x="148" y="272" label="Start" click="startCam()"/>
    </mx:Panel>
</mx:Application>
AIR3_CameraDemo.zip
[AIR, Flex Builder 3, Beta 3, Video, Camera]

+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes