Packageflash.media
Classpublic final class SoundTransform
InheritanceSoundTransform Inheritance Object

The SoundTransform class contains properties for volume and panning. The following objects contain a soundTransform property, the value of which is a SoundTransform object: Microphone, NetStream, SimpleButton, SoundChannel, SoundMixer, and Sprite.

View the examples.

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties
 PropertyDefined by
 Inheritedconstructor : 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
 Inheritedprototype : 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
Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods
 FunctionDefined by
  
SoundTransform(vol:Number = 1, panning:Number = 0)
Creates a SoundTransform object.
SoundTransform
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
Property detail
leftToLeft property
leftToLeft:Number  [read-write]

A value, from 0 (none) to 1 (all), specifying how much of the left input is played in the left speaker.

Implementation
    public function get leftToLeft():Number
    public function set leftToLeft(value:Number):void
leftToRight property
leftToRight:Number  [read-write]

A value, from 0 (none) to 1 (all), specifying how much of the left input is played in the right speaker.

Implementation
    public function get leftToRight():Number
    public function set leftToRight(value:Number):void
pan property
pan:Number  [read-write]

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 (balanced center between right and left).

Implementation
    public function get pan():Number
    public function set pan(value:Number):void
rightToLeft property
rightToLeft:Number  [read-write]

A value, from 0 (none) to 1 (all), specifying how much of the right input is played in the left speaker.

Implementation
    public function get rightToLeft():Number
    public function set rightToLeft(value:Number):void
rightToRight property
rightToRight:Number  [read-write]

A value, from 0 (none) to 1 (all), specifying how much of the right input is played in the right speaker.

Implementation
    public function get rightToRight():Number
    public function set rightToRight(value:Number):void
volume property
volume:Number  [read-write]

The volume, ranging from 0 (silent) to 1 (full volume).

Implementation
    public function get volume():Number
    public function set volume(value:Number):void
Constructor detail
SoundTransform constructor

public function SoundTransform(vol:Number = 1, panning:Number = 0)

Creates a SoundTransform object.

Parameters
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).
Class examples

The following example uses the class 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:
  1. Declare the following four properties for later use:
    1. url of type String set to the name and location of the MP3 file.
    2. soundFactory of type Sound
    3. channel of type SoundChannel
    4. positionTimer of type Timer
  2. The class constructor creates a new URLRequest instance named request which is passed the url property.
  3. A variable named soundFactory is then created and assigned to a new Sound instance.
  4. The 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.
  5. A mouseMoveHandler() event listener method is added to the stage, which does the following each time it receives a mouseMove event:
    1. Various numbers are calculated based on the x/y coordinates of the mouse.
    2. The volume and pan of the sound channel are set based on these calculated numbers using the setPan() and setVolume() methods.
    3. setPan() and setVolume() both use a variable named transform of type SoundTransform set equal to channel's soundTransform property.
    4. setPan() sets transform's pan property according to the number calculated earlier and setVolume() uses transform's volume property in a similar manner.
    5. In both setPan() and setVolume(), channel's soundTransform property is updated with the new value of transform and the volume and pan are adjusted accordingly.

Notes:

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