Packagenet.flashpunk
Classpublic class Sfx
InheritanceSfx Inheritance Object

Sound effect object used to play embedded sounds.



Public Properties
 PropertyDefined By
  complete : Function
Optional callback function for when the sound finishes playing.
Sfx
  length : Number
[read-only] Length of the sound, in seconds.
Sfx
  pan : Number
Alter the panning factor (a value from -1 to 1) of the sound during playback.
Sfx
  playing : Boolean
[read-only] If the sound is currently playing.
Sfx
  position : Number
[read-only] Position of the currently playing sound, in seconds.
Sfx
  type : String
Change the sound type.
Sfx
  volume : Number
Alter the volume factor (a value from 0 to 1) of the sound during playback.
Sfx
Public Methods
 MethodDefined By
  
Sfx(source:*, complete:Function = null, type:String = null)
Creates a sound effect from an embedded source.
Sfx
  
getPan(type:String):Number
[static] Return the global pan for a type.
Sfx
  
getVolume(type:String):Number
[static] Return the global volume for a type.
Sfx
  
loop(vol:Number = 1, pan:Number = 0):void
Plays the sound looping.
Sfx
  
play(vol:Number = 1, pan:Number = 0):void
Plays the sound once.
Sfx
  
resume():void
Resumes the sound from the position stop() was called on it.
Sfx
  
setPan(type:String, pan:Number):void
[static] Set the global pan for a type.
Sfx
  
setVolume(type:String, volume:Number):void
[static] Set the global volume for a type.
Sfx
  
stop():Boolean
Stops the sound if it is currently playing.
Sfx
Property Detail
completeproperty
public var complete:Function

Optional callback function for when the sound finishes playing.

lengthproperty 
length:Number  [read-only]

Length of the sound, in seconds.


Implementation
    public function get length():Number
panproperty 
pan:Number

Alter the panning factor (a value from -1 to 1) of the sound during playback.


Implementation
    public function get pan():Number
    public function set pan(value:Number):void
playingproperty 
playing:Boolean  [read-only]

If the sound is currently playing.


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

Position of the currently playing sound, in seconds.


Implementation
    public function get position():Number
typeproperty 
type:String

Change the sound type. This an arbitrary string you can use to group sounds to mute or pan en masse.


Implementation
    public function get type():String
    public function set type(value:String):void
volumeproperty 
volume:Number

Alter the volume factor (a value from 0 to 1) of the sound during playback.


Implementation
    public function get volume():Number
    public function set volume(value:Number):void
Constructor Detail
Sfx()Constructor
public function Sfx(source:*, complete:Function = null, type:String = null)

Creates a sound effect from an embedded source. Store a reference to this object so that you can play the sound using play() or loop().

Parameters
source:* — The embedded sound class to use or a Sound object.
 
complete:Function (default = null) — Optional callback function for when the sound finishes playing.
 
type:String (default = null)
Method Detail
getPan()method
public static function getPan(type:String):Number

Return the global pan for a type.

Parameters

type:String

Returns
Number
getVolume()method 
public static function getVolume(type:String):Number

Return the global volume for a type.

Parameters

type:String

Returns
Number
loop()method 
public function loop(vol:Number = 1, pan:Number = 0):void

Plays the sound looping. Will loop continuously until you call stop(), play(), or loop() again.

Parameters

vol:Number (default = 1) — Volume factor, a value from 0 to 1.
 
pan:Number (default = 0) — Panning factor, a value from -1 to 1.

play()method 
public function play(vol:Number = 1, pan:Number = 0):void

Plays the sound once.

Parameters

vol:Number (default = 1) — Volume factor, a value from 0 to 1.
 
pan:Number (default = 0) — Panning factor, a value from -1 to 1.

resume()method 
public function resume():void

Resumes the sound from the position stop() was called on it.

setPan()method 
public static function setPan(type:String, pan:Number):void

Set the global pan for a type. Sfx instances of this type will add this pan to their own.

Parameters

type:String
 
pan:Number

setVolume()method 
public static function setVolume(type:String, volume:Number):void

Set the global volume for a type. Sfx instances of this type will multiply their volume by this value.

Parameters

type:String
 
volume:Number

stop()method 
public function stop():Boolean

Stops the sound if it is currently playing.

Returns
Boolean