Adobe Flex 2 Language Reference - collected by Jimbob | Back to MY RESOURCES


Packageflash.media
Classpublic final class SoundChannel
InheritanceSoundChannel Inheritance EventDispatcher Inheritance Object

The SoundChannel class controls a sound in an application. Each sound playing in an Adobe® Flash® application is assigned to a sound channel, and the application can have multiple sound channels that are mixed together. The SoundChannel class contains a stop() method, properties for monitoring the amplitude (volume) of the channel, and a property for setting a SoundTransform object to the channel.

View the examples.

See also

Sound
SoundTransform


Public Properties
 PropertyDefined by
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  leftPeak : Number
[read-only] The current amplitude (volume) of the left channel, from 0 (silent) to 1 (full amplitude).
SoundChannel
  position : Number
[read-only] The current position of the playhead within the sound.
SoundChannel
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
  rightPeak : Number
[read-only] The current amplitude (volume) of the right channel, from 0 (silent) to 1 (full amplitude).
SoundChannel
  soundTransform : SoundTransform
The SoundTransform object assigned to the sound channel.
SoundChannel
Public Methods
 MethodDefined by
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event.
EventDispatcher
 Inherited
Dispatches an event into the event flow.
EventDispatcher
 Inherited
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
EventDispatcher
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
EventDispatcher
 Inherited
setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void
Sets the availability of a dynamic property for loop operations.
Object
  
stop():void
Stops the sound playing in the channel.
SoundChannel
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
 Inherited
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.
EventDispatcher
Events
 EventSummaryDefined by
 Inherited Dispatched when Flash Player gains operating system focus and becomes active.EventDispatcher
 Inherited Dispatched when Flash Player loses operating system focus and is becoming inactive.EventDispatcher
   Dispatched when a sound has finished playing.SoundChannel
Property detail
leftPeakproperty
leftPeak:Number  [read-only]

The current amplitude (volume) of the left channel, from 0 (silent) to 1 (full amplitude).

Implementation
    public function get leftPeak():Number
positionproperty 
position:Number  [read-only]

The current position of the playhead within the sound.

Implementation
    public function get position():Number
rightPeakproperty 
rightPeak:Number  [read-only]

The current amplitude (volume) of the right channel, from 0 (silent) to 1 (full amplitude).

Implementation
    public function get rightPeak():Number
soundTransformproperty 
soundTransform:SoundTransform  [read-write]

The SoundTransform object assigned to the sound channel. A SoundTransform object includes properties for setting volume, panning, left speaker assignment, and right speaker assignment.

Implementation
    public function get soundTransform():SoundTransform
    public function set soundTransform(value:SoundTransform):void

See also

Method detail
stop()method
public function stop():void

Stops the sound playing in the channel.

Event detail
soundCompleteevent 
Event object type: flash.events.Event
Event.type property = flash.events.Event.SOUND_COMPLETE

Dispatched when a sound has finished playing.

Defines the value of the type property of a soundComplete event object.

This event has the following properties:

PropertyValue
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the Event object with an event listener.
targetThe Sound object on which a sound has finished playing.
Examples

The following example loads an MP3 file, plays it, and displays information about sound events that take place as the MP3 file is loaded and played. A Timer object provides updated information about the position of the playhead every 50 milliseconds. To run this example, place a file named MySound.mp3 in the same directory as your SWF file.
package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.net.URLRequest;
    import flash.utils.Timer;

    public class SoundChannelExample extends Sprite {
        private var url:String = "MySound.mp3";
        private var soundFactory:Sound;
        private var channel:SoundChannel;
        private var positionTimer:Timer;

        public function SoundChannelExample() {
            var request:URLRequest = new URLRequest(url);
            soundFactory = new Sound();
            soundFactory.addEventListener(Event.COMPLETE, completeHandler);
            soundFactory.addEventListener(Event.ID3, id3Handler);
            soundFactory.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
            soundFactory.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            soundFactory.load(request);

            channel = soundFactory.play();
            channel.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);

            positionTimer = new Timer(50);
            positionTimer.addEventListener(TimerEvent.TIMER, positionTimerHandler);
            positionTimer.start();
        }
        

        private function positionTimerHandler(event:TimerEvent):void {
            trace("positionTimerHandler: " + channel.position.toFixed(2));
        }

        private function completeHandler(event:Event):void {
            trace("completeHandler: " + event);
        }

        private function id3Handler(event:Event):void {
            trace("id3Handler: " + event);
        }

        private function ioErrorHandler(event:Event):void {
            trace("ioErrorHandler: " + event);
            positionTimer.stop();       
        }

        private function progressHandler(event:ProgressEvent):void {
            trace("progressHandler: " + event);
        }

        private function soundCompleteHandler(event:Event):void {
            trace("soundCompleteHandler: " + event);
            positionTimer.stop();
        }
    }
}





collected by Jimbob 2007.05