Macromedia Flex Macromedia Flex
Flex & Video: Using a WebCam
  Home

Sep 15, 2005 - Flex & Video: Using a WebCam
Two methods for instantiating video in your Flex Application.

You don't need a VideoObject to send stream to flashcom. But you need itto see what is going to server :)

Video class can not be instantiated using ActionScript. You need to have a Video Symbol in your swf.

There are two methods:

1) Use MediaDisplay
2) Create a swf with Video symbol and embed in Flex app.

First method would work without much effort but file size might be more, because entire MediaDisplay code would be in swf even though you won't be using any MediaDisplay functionality.

Second method would take 5-10 minutes more effort for creating a swf with Video symbol using Macromedia Flash IDE. But final output of your application would be small.

I am going to show you both ways here. See the following code and also at attached files:



1) ##CameraUsingMediaDisplay.mxml##

<?xml version="1.0" encoding="iso-8859-1"?>
<mx:Application xmlns:mx="
http://www.macromedia.com/2003/mxml"
width="600" height="600" creationComplete="onAppInit()" >
   
    <mx:Script>
        <![CDATA[
           
            var video:Video;
            var camera:Camera;
            var netConnection:NetConnection;
            var netStream:NetStream;
           
            function onAppInit()
            {
                //Get there reference of video object, check
MediaDisplay.as in FlexforFlash.zip.
                video = mediaDisplay["_videoHolder"]._video;
          
                //Make a new connection object
                netConnection = new NetConnection();
  
                //Connect to the service
     
//my_nc.connect("rtmp://server.com/yourapp/theInstance");
            }  
           
            function startCamera()
            {
                camera = Camera.get();
                video.attachVideo(camera);
               
                 //netStream = new NetStream(netConnection);
                 //netStream.attachVideo(camera);
                //netStream.publish("myCameraStream", "live");
               
            }
        ]]>
    </mx:Script>
    <mx:MediaDisplay id="mediaDisplay" width="340"
height="280"></mx:MediaDisplay>
    <mx:Button label="Start Camera" click="startCamera()"/>
   
</mx:Application>


2) ##CameraUsingVideoSymbol.mxml##

<?xml version="1.0" encoding="iso-8859-1"?>
<mx:Application xmlns:mx="
http://www.macromedia.com/2003/mxml"
width="600" height="600" creationComplete="onAppInit()" >
   
    <mx:Script>
        <![CDATA[
           
            //emebd videoHolder.swf which contains a movieclip
symbol 'videoHolder'. videoHolder movieclip is wrapper around Video
object
            [Embed(source="videoHolder.swf", symbol="videoHolder")]
            var videoHolder:String;
           
            var video:Video;
            var camera:Camera;
            var netConnection:NetConnection;
            var netStream:NetStream;
           
                
            function onAppInit()
            {
                //_video is the instance name of Video object inside
videoHolder movieclip.
                video = image.content._video;
          
                //Make a new connection object
                netConnection = new NetConnection();
  
                //Connect to the service
     
//my_nc.connect("rtmp://server.com/yourapp/theInstance");
            }  
           
            function startCamera()
            {
                camera = Camera.get();
                video.attachVideo(camera);
               
                 //netStream = new NetStream(netConnection);
                 //netStream.attachVideo(camera);
                //netStream.publish("myCameraStream", "live");
               
            }
        ]]>
    </mx:Script>
    <mx:Image id="image" contentPath="videoHolder" width="340"
height="280" />
    <mx:Button label="Start Camera" click="startCamera()"/>
   
</mx:Application>

File Details
Created On Sep, 15, 2005 by Tariq Ahmed
Last Modified On Sep, 15, 2005 by Tariq Ahmed
Group: Tips and Articles
Flex Versions: All
Category: Integration
Type: Tip
Difficulty: Advanced
Keywords:
404 Not Found

Not Found

The requested URL /cfset2.txt was not found on this server.


Apache/2.2.16 (Debian) Server at 199.19.94.194 Port 80