package { import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.*; import flash.media.Sound; import flash.media.SoundChannel; import flash.media.SoundTransform; import flash.net.URLRequest; import flash.utils.Timer; public class SoundTransformExample extends Sprite { private var url:String = "MySound.mp3"; private var soundFactory:Sound; private var channel:SoundChannel; private var positionTimer:Timer; public function SoundTransformExample() { stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; var request:URLRequest = new URLRequest(url); soundFactory = new Sound(); soundFactory.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); soundFactory.load(request); channel = soundFactory.play(); stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler); } private function ioErrorHandler(event:Event):void { trace("ioErrorHandler: " + event); } private function setPan(pan:Number):void { trace("setPan: " + pan.toFixed(2)); var transform:SoundTransform = channel.soundTransform; transform.pan = pan; channel.soundTransform = transform; } private function setVolume(volume:Number):void { trace("setVolume: " + volume.toFixed(2)); var transform:SoundTransform = channel.soundTransform; transform.volume = volume; channel.soundTransform = transform; } private function mouseMoveHandler(event:MouseEvent):void { var halfStage:uint = Math.floor(stage.stageWidth / 2); var xPos:uint = event.stageX; var yPos:uint = event.stageY; var value:Number; var pan:Number; if (xPos > halfStage) { value = xPos / halfStage; pan = value - 1; } else if (xPos < halfStage) { value = (xPos - halfStage) / halfStage; pan = value; } else { pan = 0; } var volume:Number = 1 - (yPos / stage.stageHeight); setVolume(volume); setPan(pan); } } }
flash 外部加载mp3 标准代码
最新推荐文章于 2015-08-01 18:24:49 发布