| Package | flash.media |
| Class | public final class SoundTransform |
| Inheritance | SoundTransform Object |
soundTransform property,
the value of which is a SoundTransform object: Microphone, NetStream, SimpleButton,
SoundChannel, SoundMixer, and Sprite.
View the examples.
| Property | Defined by | ||
|---|---|---|---|
![]() | constructor : Object
A reference to the class object or constructor function for a given object instance.
| Object | |
| leftToLeft : Number
A value, from 0 (none) to 1 (all), specifying how much of the left input is played in the
left speaker.
| SoundTransform | ||
| leftToRight : Number
A value, from 0 (none) to 1 (all), specifying how much of the left input is played in the
right speaker.
| SoundTransform | ||
| pan : Number
The left-to-right panning of the sound, ranging from -1 (full pan left)
to 1 (full pan right).
| SoundTransform | ||
![]() | prototype : Object
[static]
A reference to the prototype object of a class or function object.
| Object | |
| rightToLeft : Number
A value, from 0 (none) to 1 (all), specifying how much of the right input is played in the
left speaker.
| SoundTransform | ||
| rightToRight : Number
A value, from 0 (none) to 1 (all), specifying how much of the right input is played in the
right speaker.
| SoundTransform | ||
| volume : Number
The volume, ranging from 0 (silent) to 1 (full volume).
| SoundTransform | ||
| Function | Defined by | ||
|---|---|---|---|
|
Creates a SoundTransform object.
| SoundTransform | ||
![]() |
Indicates whether an object has a specified property defined.
| Object | |
![]() |
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter.
| Object | |
![]() |
Indicates whether the specified property exists and is enumerable.
| Object | |
![]() |
Sets the availability of a dynamic property for loop operations.
| Object | |
![]() |
Returns the string representation of the specified object.
| Object | |
![]() |
Returns the primitive value of the specified object.
| Object | |
leftToLeft:Number [read-write] public function get leftToLeft():Number
public function set leftToLeft(value:Number):void
leftToRight:Number [read-write] public function get leftToRight():Number
public function set leftToRight(value:Number):void
pan:Number [read-write] public function get pan():Number
public function set pan(value:Number):void
rightToLeft:Number [read-write] public function get rightToLeft():Number
public function set rightToLeft(value:Number):void
rightToRight:Number [read-write] public function get rightToRight():Number
public function set rightToRight(value:Number):void
volume:Number [read-write] public function get volume():Number
public function set volume(value:Number):void
public function SoundTransform(vol:Number = 1, panning:Number = 0)
vol:Number (default = 1) — The volume, ranging from 0 (silent) to 1 (full volume).
|
|
panning:Number (default = 0) — The left-to-right panning of the sound, ranging from -1 (full pan left)
to 1 (full pan right). A value of 0 represents no panning (center).
|
SoundTransformExample to change the
volume and pan with each mouseMove event over the stage as an MP3 file is played. This is
accomplished using the following steps:
url of type String set to the name and location of the MP3 file.soundFactory of type Soundchannel of type SoundChannelpositionTimer of type Timerrequest which is passed
the url property.soundFactory is then created and assigned to a new Sound instance.load() method is then passed request and then play() is
called, which returns a SoundFactory object that is assigned to channel so the audio from
the MP3 can be heard as it is played.mouseMoveHandler() event listener method is added to the stage, which does the following
each time it receives a mouseMove event:() and setVolume() methods.setPan() and setVolume() both use a variable named transform
of type SoundTransform set equal to channel's soundTransform property.setPan() sets transform's pan property according to the number
calculated earlier and setVolume() uses transform's volume property in
a similar manner.setPan() and setVolume(), channel's
soundTransform property is updated with the new value of transform and the
volume and pan are adjusted accordingly.Notes:
MySound.mp3 be placed in the same directory as your SWF file.
package {
import flash.utils.Timer;
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.*;
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() {
var request:URLRequest = new URLRequest(url);
soundFactory = new Sound();
soundFactory.load(request);
channel = soundFactory.play();
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
}
private function setPan(pan:Number):void {
trace("setPan: " + pan);
var transform:SoundTransform = channel.soundTransform;
transform.pan = pan;
channel.soundTransform = transform;
}
private function setVolume(volume:Number):void {
trace("setVolume: " + volume);
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.localX;
var yPos:uint = event.localY;
var value:Number;
var pan:Number;
if(xPos > halfStage) {
value = (xPos - halfStage) / halfStage;
pan = -(value * 1);
} else if(xPos == halfStage) {
pan = 0;
} else {
value = xPos / halfStage;
pan = 1-(value * 1);
}
var volume:Number = 1 - (yPos / stage.stageHeight);
setVolume(volume);
setPan(pan);
}
}
}
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/labs/flashauthoringpreview/flash/media/SoundTransform.html