准备工具:

Flash Media Server..

Flash 8 && Flash 8 Player

一个摄像头,一个麦克.

打开FLASH,新建一个FLASH文档.

CTRL + L调出库..在库的右上角有个三角,点一下.然后选择"新建视频元件";

命名为:video

在主场景里新建2个图层,一个名字叫 video_record,另一个叫video_play;

将库里的视频元件分别拖到这2个图层中.起名字叫video_r和video_p.video_r是用来录视频的.video_p是用来放视频的.

(下面起新建MC啊,或命名一类的我就不写了.只做程序介绍.如果连MC命名都不知道的话相信也看不懂这教程.大家见谅 :)

程序部分:

var server_uri:String = "rtmp://localhost/tensharp"; 
//FMS地址; 

var videoName:String = "KeeRula"; 
//视频名. 

var my_nc:NetConnection = new NetConnection (); 
//新建一个连接对象,用来连接FMS; 

my_nc.connect (server_uri); 
//连接FMS; 

var my_ns:NetStream = new NetStream (my_nc); 
//新建流,用来捕获和播放视频; 

var my_cam:Camera = Camera.get (); 
video_r.attachVideo (my_cam); 
//获得慑像头,并将摄像头获取的视频载入到video_r里. 

my_cam.setQuality (1024, 90); 
//设置带宽和质量; 

var my_mic:Microphone = Microphone.get (); 
//获得MIC; 

my_ns.attachVideo (my_cam); 
my_ns.attachAudio (my_mic); 
//将摄像头图象和MIC声音装载到流. 

video_p._visible = false; 
//将播放窗口设置为不可见. 
my_nc.onStatus = function (thisObj:Object) 
{ 
//trace (thisObj.code); 
if (thisObj.code == "NetConnection.Connect.Success") 
{ 
RecordStop ("空闲中"); 
//执行录制停止方法.并将状态设置为空闲 
} 
else 
{ 
trace ("错误:服务器未启动或URI输入错误."); 
} 
} 
//onStatus这里是指服务器的连接状态. 

function Record () 
{ 
video_r._visible = true; 
//将录制窗口设为可见. 
video_p._visible = false; 
//播放窗口设置为不可见. 
my_ns.publish (videoName, "record"); 
//关键就在这句了.写了这么多全围绕它来的.record为录制. 
StreamInfo ("NowRecord"); 
//执行StreamInfo方法,并将参数设置为NowRecord; 
btn_pr.btn_text.text = "停止"; 
//按钮文字:停止. 
RecordInterval = setInterval (RecordTime, 1000); 
//统计录制时间. 
} 
//方法:录制. 

var timeNum:Number = 0; 
//录制时间. 

function RecordTime () 
{ 
timeNum ++; 
txt_status.text = "正在录制" + " " + "时间:" + Math.floor (timeNum / 60) + "分" + (timeNum % 60) + "秒"; 
} 
//方法:录制时间统计. 
my_nc.onStatus = function (thisObj:Object) 
{ 
//trace (thisObj.code); 
if (thisObj.code == "NetConnection.Connect.Success") 
{ 
RecordStop ("空闲中"); 
//执行录制停止方法.并将状态设置为空闲 
} 
else 
{ 
trace ("错误:服务器未启动或URI输入错误."); 
} 
} 
//onStatus这里是指服务器的连接状态. 

function Record () 
{ 
video_r._visible = true; 
//将录制窗口设为可见. 
video_p._visible = false; 
//播放窗口设置为不可见. 
my_ns.publish (videoName, "record"); 
//关键就在这句了.写了这么多全围绕它来的.record为录制. 
StreamInfo ("NowRecord"); 
//执行StreamInfo方法,并将参数设置为NowRecord; 
btn_pr.btn_text.text = "停止"; 
//按钮文字:停止. 
RecordInterval = setInterval (RecordTime, 1000); 
//统计录制时间. 
} 
//方法:录制. 

var timeNum:Number = 0; 
//录制时间. 

function RecordTime () 
{ 
timeNum ++; 
txt_status.text = "正在录制" + " " + "时间:" + Math.floor (timeNum / 60) + "分" + (timeNum % 60) + "秒"; 
} 
//方法:录制时间统计. 
function RecordStop (__status:String) 
{ 
//__status是当前状态文字. 
txt_status.text = "当前状态:" + __status; 
btn_pr.btn_text.text = "录制"; 
StreamInfo ("NowStop"); 
//执行StreamInfo方法..并将参数设置为NowStop; 
clearInterval (RecordInterval); 
timeNum = 0; 
//不录了..要把统计时间清空. 
if (__status == "录制完成") 
{ 
Finished (); 
} 
//这个应该不用偶说了.. 
} 
//方法:空闲或录制完成. 

function Finished () 
{ 
my_ns.close(); 
//完成了..就要关闭录制. 
var thisObj = this; 
var FinishAlert:MovieClip = _root.attachMovie ("Alert", "FinishAlert", 100); 
//这个是一个弹出框.具体看库里的MC:Alert. 
with (FinishAlert) 
{ 
alertTitle.html = true; 
alertTitle.htmlText = "" + "录制完成!" + ""; 
info.text = "录制完成..请选择下一步操作." 
_x = video_r._x + (video_r._width - _width) / 2; 
_y = video_r._y + (video_r._height - _height) / 2; 
btn_sub.btn_txt.text = "播放"; 
btn_cln.btn_txt.text = "重录"; 
btn_sub.onRelease = function () 
{ 
thisObj.PlayVideo (); 
thisObj.closeAlert (FinishAlert); 
} 
btn_cln.onRelease = function () 
{ 
thisObj.Record (); 
thisObj.closeAlert (FinishAlert); 
} 
closed.onRelease = function () 
{ 
thisObj.closeAlert (FinishAlert); 
} 
} 
btn_pr.enabled = false; 
//把按钮设为不可点. 
} 
//方法:录制完成. 

function closeAlert (__alert:MovieClip) 
{ 
btn_pr.enabled = true; 
unloadMovie (__alert); 
} 
//关闭那个Alert用的. function StreamInfo (__status:String) 
{ 
btn_pr.onRelease = function () 
{ 
if (__status == "NowRecord") 
{ 
RecordStop ("录制完成"); 
} 
else if (__status == "NowStop") 
{ 
Record (); 
} 
else if (__status == "NowPlay") 
{ 
Record (); 
} 
} 
} 
//嘿嘿..如果把上面的仔细看了的话这个就不用我说了吧.^_^ 

function PlayVideo () 
{ 
txt_status.text = "当前状态:" + "正在播放..."; 
StreamInfo ("NowPlay") 
video_r._visible = false; 
video_p._visible = true; 
video_p.attachVideo (my_ns); 
//将视频载到播放窗口中. 
my_ns.play (videoName); 
//开始播放. 
btn_pr.btn_text.text = "重录"; 
my_ns.onStatus = function (PlayInfo) 
{ 
if (PlayInfo.code == "NetStream.Play.Stop") 
{ 
my_ns.seek (0); 
my_ns.pause(); 
txt_status.text = "当前状态:" + "播放完成..."; 
} 
} 
//流状态信息...详细的请自己 trace (PlayInfo.code); 
} 
//方法:播放视频. 
//需要注意的是用FMS播放的时候不用写路径.因为FMS录的视频直接存在FMS默认的流文件目录里了. 
//录的视频的存放路径:FMS安装目录:/application/站点/streams/_definst_



如果上面看个差不多了可以自己动手做一下了.祝大家好运 (By:KeeRula)(: