[AS3]AS3下的麦克风接口【flash.media.Microphone 类】源代码示
[AS3]AS3下的麦克风接口【flash.media.Microphone 类】源代码示例
[AS3]AS3下的麦克风接口【flash.media.Microphone 类】源代码示例
- package {
- import flash.display.Shape;
- import flash.display.Sprite;
- import flash.events.ActivityEvent;
- import flash.events.Event;
- import flash.media.Microphone;
- public class SoundGame extends Sprite
- {
- private var main:Sprite;
- private var mic:Microphone;
- private var minHigh:int = 0;
- private var intervalValue:int = 0;
- public function SoundGame()
- {
- init();
- }
- //初始化
- private function init():void{
- initMic();
- createSky();
- createLand();
- createMain();
- }
- //初始化麦克风
- private function initMic():void{
- mic = Microphone.getMicrophone();
- mic.setSilenceLevel(30,0);
- mic.setLoopBack();
- mic.addEventListener(ActivityEvent.ACTIVITY,micActivityHandle);
- }
- //创建操作
- private function createMain():void{
- var mainContainer:Sprite = new Sprite;
- main = new Sprite;
- main.graphics.beginFill(0xffffff);
- main.graphics.drawCircle(-2,-4,4);
- mainContainer.x = 100;
- mainContainer.y = 250;
- mainContainer.addChild(main);
- addChild(mainContainer);
- main.addEventListener(Event.ENTER_FRAME,frameHandle);
- }
- //创建天
- private function createSky():void{
- var shape:Shape = new Shape;
- shape.graphics.beginFill(0x6699cc,1);
- shape.graphics.drawRect(0,0,400,250);
- addChild(shape);
- }
- //创建陆地
- private function createLand():void{
- var shape:Shape = new Shape;
- shape.graphics.beginFill(0x002222,1);
- shape.graphics.drawRect(0,250,400,150);
- addChild(shape);
- }
- //麦克风活跃处理
- private function micActivityHandle(e:ActivityEvent):void{
- if(e.activating && intervalValue == 0){
- intervalValue = mic.activityLevel / 5;
- }
- }
- //持续处理
- private function frameHandle(e:Event):void{
- if(intervalValue == 0) return;
- main.y -= intervalValue;
- intervalValue --;
- if(intervalValue == 0) intervalValue -= 1;
- //落地
- var min:int = - minHigh;
- if(min < main.y){
- main.y = min;
- intervalValue = 0;
- }
- }
- }
- }
[AS3]AS3下的麦克风接口【flash.media.Microphone 类】源代码示例
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...