当前位置: 首页 > 图文教程 > Flash动画 > Flash实例教程 > Flash实例教程:启动摄像头拍照动画

Flash实例教程
Flash教程:AS制作加载外部.swf影片的视频播放器
FlashAS3.0实例教程:喷泉动画特效
Flash cs3仿真艺术设计2.5:压扁与拉伸运用
Flash cs3仿真艺术设计2.6:轻松制作飞舞的蝴蝶
Flash CS4教程:AS3制作非常漂亮的曲线
Flash实例:AS3制作茶杯震动动画
Flash教程:鼠标点击显示打散动画
Flash实例教程:鼠标感应放大缩小动画
Flash实例教程:启动摄像头拍照动画
Flash AS3教程:制作文字飞出动画
Flash CS3教程:线性渐变模糊运动动画特效
Flash动画制作实例:不间断滚动图片动画
Flash AS3简单制作百叶窗图片特效
Flash AS3简单制作图片缓动特效动画
Flash AS3简单制作跟随鼠标缓动运动的圆
Flash轻松制作照片上有水纹波动动画
Flash实例:庆祝祖国60华诞烟花动画
Flash CS4教程:旋转的3D立方体动画
Flash实例教程:好看的旋转文字动画
Flash实例教程:低排放高节能汽车广告动画

Flash实例教程:启动摄像头拍照动画


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-01   浏览: 322 ::
收藏到网摘: n/a

Flash实例教程:启动摄像头拍照动画。大家请看效果:(如果你的机器的摄像头已经打开)

源文件下载:/upload/tech/20091001/20091001060405_934815ad542a4a7c5e8a2dfa04fea9f5.zip

1. Create a new flash file (Actionscript 3.0) and save it as captureWebcam.fla.

2. Rename ‘layer 1′ to ‘button’. Create a button on the stage, convert it to a movie clip and give it an instance name of capture_mc.

3. Create a new layer named ‘actions’ and with its first frame selected open the actions panel.
All that we are going to do now happens in the actionscript code.

4. First we initialize a webcam by attaching a camera to a Video object that we add to the stage:

1.var cam:Camera = Camera.getCamera();
2.var video:Video = new Video(320,240);
3.video.attachCamera(cam);
4.video.x = 20;
5.video.y = 20;
6.addChild(video);
5. Then, we need to use the Bitmap and BitmapData classes to store the image that we want to capture and display on the stage.
We start by importing the Bitmap and BitmapData classes:

1.import flash.display.Bitmap;
2.import flash.display.BitmapData;
6. Then create a new BitmapData object of the same proportions of the video object to store the BitmapData captured from the playing webcam.
And create a bitmap object to display the data from the BitmapData object and add it to the stage.

1.var bitmapData:BitmapData = new BitmapData(video.width,video.height);
2. 
3.var bitmap:Bitmap = new Bitmap(bitmapData);
4.bitmap.x = 360;
5.bitmap.y = 20;
6.addChild(bitmap);
7. Finally, after setting its buttonMode property to true, we add a Click event listener to our button. This event is handled by the captureImage function that draws the image that is currently displaying from the webcam into our bitmapData object.

1.capture_mc.buttonMode = true;
2.capture_mc.addEventListener(MouseEvent.CLICK,captureImage);
3. 
4.function captureImage(e:MouseEvent):void {
5.   bitmapData.draw(video);
6.}
8. Here is the final code :

01.import flash.display.Bitmap;
02.import flash.display.BitmapData;
03. 
04.var cam:Camera = Camera.getCamera();
05.var video:Video = new Video(320,240);
06.video.attachCamera(cam);
07.video.x = 20;
08.video.y = 20;
09.addChild(video);
10. 
11.var bitmapData:BitmapData = new BitmapData(video.width,video.height);
12. 
13.var bitmap:Bitmap = new Bitmap(bitmapData);
14.bitmap.x = 360;
15.bitmap.y = 20;
16.addChild(bitmap);
17. 
18.capture_mc.buttonMode = true;
19.capture_mc.addEventListener(MouseEvent.CLICK,captureImage);
20. 
21.function captureImage(e:MouseEvent):void {
22.   bitmapData.draw(video);
23.}