Home » Actionscripts library » Sound Object
|
A better control over sound Object
// an empty mc linkage must exist in library
_root.attachMovie( "empty", "empty", 100 )
function SoundObj()
{
this.count = 0;
this.addSound = addSound
}
function addSound(sound_id)
{
_root.empty.duplicateMovieClip(sound_id,this.count);
obj = _root[sound_id];
obj.sound = new Sound(obj);
obj.sound.attachSound(sound_id);
this.count+=1;
}
XSound = new SoundObj();
// Usage
// XSound.addSound( linkage_name_of_the_sound )
// after that a new object is created names as the
// linkage_name_of_the_sound
// this objcet can accept diferents values
// for the ex: .setVolume(x)
// that only affects to it and not to
// all sounds
//
XSound.addSound("track1");
XSound.addSound("track2");
// to start track1
// track1.sound.start()Posted by: Pedro Aguilar | website http://www.xperiments.com |
// Credit to Michael Tapson (earlier post) for most of the development of this
// script. I have modified it to be a part of the Sound object's prototype,
// and thus, it will work with any sound clip you have.
Sound.prototype.fadeup = function ( fadespeed, maxLevel ) {
var SndIntervalID;
clearInterval ( SndIntervalID );
SndIntervalID = setInterval ( this, "upOne", fadespeed, maxLevel );
// BUMP VOLUME UP
Sound.prototype.upOne = function ( maxLevel ) {
varSnd = this.getVolume();
if ( varSnd < maxLevel ){
this.setVolume ( varSnd + 1 );
}else{
clearInterval ( SndIntervalID );
}
updateAfterEvent();
}
}
Sound.prototype.fadedown = function ( fadespeed, minLevel ) {
var SndIntervalID;
clearInterval ( SndIntervalID );
SndIntervalID = setInterval ( this, "downOne", fadespeed, minLevel );
// BUMP VOLUME DOWN
Sound.prototype.downOne = function ( minLevel ) {
varSnd = this.getVolume();
if (varSnd > minLevel){
this.setVolume ( varSnd - 1 );
}else{
clearInterval ( SndIntervalID );
}
updateAfterEvent();
}
}
// Usage:
// mySound.fadeDown(fadeSpeed, minLevel)
// mysound.fadeUp(fadeSpeed, maxLevel)
//
// Parameters:
// fadeSpeed - A number higher than 1 that determines the length of
// time in which the sound will fade in or out. The
// higher the number, the longer the fade.
// minLevel - A number between 0 and 100. This is the lowest volume
// to which the volume will fade. (Only in fadeDown)
// maxLevel - A number between 0 and 100. This is the highest volume
// to which the volume will fade. (Only in fadeUp)
//
// Example:
// s = new Sound();
// s.attachSound("linkedSound");
// s.fadeDown(20, 0);
Posted by: J. Tomasino | website http://www.aloneone.com |
|
You could use the sound object as follows: 1) Set your sound up in frame 1: s = new Sound();
s.attachSound("buzzSound");
onClipEvent (enterFrame) {
if (_root.threeOfAKind==true) {
_root.s.start();
} else {
_root.s.stop();
}
}
on (press) {
_root.threeOfAKind=true;
}
on (release) {
_root.threeOfAKind=false;
}
Posted by: No name | website http:// |
|
Attached sounds do not play if the SWF containing the sound is loaded using the loadMovie action. For example, the following ActionScript attaches and plays a sound asset which has been exported with the linkage name "mySound": soundContainer = new Sound();
soundContainer.attachSound("mySound");
soundContainer.start();
Solution In the original FLA file, add the keyword 'this' to the new Sound constructor, as follows: soundContainer = new Sound(this);
soundContainer.attachSound("mySound");
soundContainer.start();
Posted by: No name | website http:// |
//s=your sound s= new Sound(this);s.attachSound("yoursoundslinkagename"); //now, for the controling vars _root.setPan(number); _root.setVolume(number); //now for using them-make a button //put in button sctions: on(press){ s.setPan(Math.random()*100); } //sets random pan //or on(press){ s.setVolume(Math.random()*100); } //sets random volume //or both on(press){ s.setVolume(Math.random()*100); s.setPan(Math.random()*100); } //or to set it to a set number-make an input text field //and give it the Var: "_root.txt" on(press){ s.setPan(_root.txt); } //or on(press){ s.setVolume(_root.txt); } //or, make 2 boxes of input text, and give one the Var:"_root.volume" and the other "_root.pan" on(press){ s.setPan(_root.pan); s.setVolume(_root.volume); } //thats all folks! Posted by: Alcatraz5 | website http://www.newgrounds.com |

