leftToLeft:Number
[read-write]
Player 版本 : | Flash Player 9 |
从 0(无)至 1(全部)的值,指定了左输入在左扬声器里播放的量。
实现
public function get leftToLeft():Number
public function set leftToLeft(value:Number):void
leftToRight:Number
[read-write]
Player 版本 : | Flash Player 9 |
从 0(无)至 1(全部)的值,指定了左输入在右扬声器里播放的量。
实现
public function get leftToRight():Number
public function set leftToRight(value:Number):void
pan:Number
[read-write]
Player 版本 : | Flash Player 9 |
声音从左到右的平移,范围从 -1(左侧最大平移)至 1(右侧最大平移)。 值 0 表示没有平移(在左侧和右侧之间平衡居中)。
实现
public function get pan():Number
public function set pan(value:Number):void
rightToLeft:Number
[read-write]
Player 版本 : | Flash Player 9 |
从 0(无)至 1(全部)的值,指定了右输入在左扬声器里播放的量。
实现
public function get rightToLeft():Number
public function set rightToLeft(value:Number):void
rightToRight:Number
[read-write]
Player 版本 : | Flash Player 9 |
从 0(无)至 1(全部)的值,指定了右输入在右扬声器里播放的量。
实现
public function get rightToRight():Number
public function set rightToRight(value:Number):void
以下示例将加载并播放 MP3 文件。 当播放 MP3 文件时,移动鼠标;将鼠标移到舞台上时,音量和平移会发生变化。 若要运行此示例,请将一个名为 MySound.mp3 的文件放在 SWF 文件所在的同一目录中。
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);
}
}
}