Slowburn
01-31-2004, 05:49 PM
Hi All,
I'm creating a little sound Library for me to use....
I'm stuck on something here, and it's getting a little frustrating.
I have an object, and within that object I'm attaching sounds (this is fine)
Each sound can be played at at specified volume or pan (this is fine aswell), but I would like to be able to control the sounds volume and pan by group (the object);
This is what I have:
soundLib = function ()
{
this.groupVolume = null;
this.groupPan = null;
this = new Object();
};
soundLib.prototype.addTracks = function ()
{
for (var i=0; i<arguments.length; i++) {
this[arguments[i]] = new Sound(this[arguments[i]]);
this[arguments[i]].attachSound(arguments[i]);
this[arguments[i]].setVolume(100);
this[arguments[i]].setPan(0);
this[arguments[i]].play = function (/* {volume: 100, pan: 0, offset: 0, loop: 0}*/)
{
var settings = arguments[0];
var iVol = (settings.volume != undefined || settings.volume != null ? settings.volume : 100);
var iPan = (settings.pan != undefined || settings.pan != null ? settings.pan : 0);
var iOffset = (settings.offset != undefined || settings.offset != null ? settings.offset : 0);
var iLoop = (settings.loop != undefined || settings.loop != null ? settings.loop : 0);
/* Problem on line below */
trace(this.getGroupVolume());
this.setVolume(iVol);
this.setPan(iPan);
this.start(iOffset, iLoop);
}
}
}
soundLib.prototype.setGroupVolume = function (iVol)
{
this.groupVolume = iVol;
}
soundLib.prototype.getGroupVolume = function ()
{
return this.groupVolume;
}
soundLib.prototype.setGroupPan = function (iPan)
{
this.groupPan = iPan;
}
soundLib.prototype.getGroupPan = function ()
{
return this.groupPan;
}
soundLib.prototype.resetGroupVolume = function ()
{
this.groupVolume = null;
}
soundLib.prototype.resetGroupPan = function ()
{
this.groupPan = null;
}
soundLib.prototype.resetAll = function ()
{
this.groupVolume = null;
this.groupPan = null;
}
Effects = new soundLib();
Effects.addTracks("damage", "explode");
Effects.damage.play({volume: 100, pan: 0, offset: 0, loop: 0});
What this is supposed to do is set the group volume or pan so it overrides any input (arguments) for the sound playing.
So if I set:
Effects.setGroupVolume(20);
Effects.damage.play({volume: 100, pan: 0, offset: 0, loop: 0});
The volume should play at 20 NOT 100, as set in the arguments of the play function.
In the code below the line "/* Problem on line below */" I'm trying to get the group volume variable, bu it always comes back undefined.
How do I target this properly? Anyone?
Cheers.
I'm creating a little sound Library for me to use....
I'm stuck on something here, and it's getting a little frustrating.
I have an object, and within that object I'm attaching sounds (this is fine)
Each sound can be played at at specified volume or pan (this is fine aswell), but I would like to be able to control the sounds volume and pan by group (the object);
This is what I have:
soundLib = function ()
{
this.groupVolume = null;
this.groupPan = null;
this = new Object();
};
soundLib.prototype.addTracks = function ()
{
for (var i=0; i<arguments.length; i++) {
this[arguments[i]] = new Sound(this[arguments[i]]);
this[arguments[i]].attachSound(arguments[i]);
this[arguments[i]].setVolume(100);
this[arguments[i]].setPan(0);
this[arguments[i]].play = function (/* {volume: 100, pan: 0, offset: 0, loop: 0}*/)
{
var settings = arguments[0];
var iVol = (settings.volume != undefined || settings.volume != null ? settings.volume : 100);
var iPan = (settings.pan != undefined || settings.pan != null ? settings.pan : 0);
var iOffset = (settings.offset != undefined || settings.offset != null ? settings.offset : 0);
var iLoop = (settings.loop != undefined || settings.loop != null ? settings.loop : 0);
/* Problem on line below */
trace(this.getGroupVolume());
this.setVolume(iVol);
this.setPan(iPan);
this.start(iOffset, iLoop);
}
}
}
soundLib.prototype.setGroupVolume = function (iVol)
{
this.groupVolume = iVol;
}
soundLib.prototype.getGroupVolume = function ()
{
return this.groupVolume;
}
soundLib.prototype.setGroupPan = function (iPan)
{
this.groupPan = iPan;
}
soundLib.prototype.getGroupPan = function ()
{
return this.groupPan;
}
soundLib.prototype.resetGroupVolume = function ()
{
this.groupVolume = null;
}
soundLib.prototype.resetGroupPan = function ()
{
this.groupPan = null;
}
soundLib.prototype.resetAll = function ()
{
this.groupVolume = null;
this.groupPan = null;
}
Effects = new soundLib();
Effects.addTracks("damage", "explode");
Effects.damage.play({volume: 100, pan: 0, offset: 0, loop: 0});
What this is supposed to do is set the group volume or pan so it overrides any input (arguments) for the sound playing.
So if I set:
Effects.setGroupVolume(20);
Effects.damage.play({volume: 100, pan: 0, offset: 0, loop: 0});
The volume should play at 20 NOT 100, as set in the arguments of the play function.
In the code below the line "/* Problem on line below */" I'm trying to get the group volume variable, bu it always comes back undefined.
How do I target this properly? Anyone?
Cheers.