Groups | Blog | Home
all groups > flash actionscript > april 2006 >

flash actionscript : volume slider / pause play


Broose
4/2/2006 5:12:32 PM
I need to figure out how to get the a volume slider to work on the code
below. I have everything playing and working but having difficulty getting
the volume slider to work. I have a button created called volume2.png that I
have not imported yet that is the knob on the slider that will move.

I also need to make the pause button turn into a play button when clicked on
when the music is playing and pause the music then if clicked on again start
playing the music again and turn the button back in to a pause button.

var musicFolderName:String = "Music/";
var curTrackNum:Number = 0;
var curPlaybackPos:Number;
var mySound:Sound;
var trackInfoArray:Array;
var trackInfoTracker:Number = 0;
var infoChangerInterv:Number;

function playMusicFunc() {
mySound = new Sound();
mySound.loadSound((musicFolderName + "song" + curTrackNum + ".mp3") ,
true);

mySound.onID3 = function() {
trackInfoArray = new Array();

trackInfoArray[0] = "Track : " + mySound.id3.TIT2;
trackInfoArray[1] = "Track " + (curTrackNum + 1) + " of " +
myLV.totalTracks;

clearInterval(infoChangerInterv);
infoChangerInterv = setInterval(infoChanger, 5000);
infoChanger();
}


if (curTrackNum == (myLV.totalTracks - 1)) {
nextTrack.enabled = false;
nextTrack._alpha = 50;
} else {
nextTrack.enabled = true;
nextTrack._alpha = 100;

}
if (curTrackNum == 0) {
prevTrack.enabled = false;
prevtrack._alpha = 50;
} else {
prevTrack.enabled = true;
prevTrack._alpha = 100;
}

}

function infoChanger() {
trackInfo.text = trackInfoArray[trackInfoTracker];

if (trackInfoTracker == (trackInfoArray.length - 1)) {
trackInfoTracker = 0;
} else {
trackInfoTracker++;
}


}

var myLV:LoadVars = new LoadVars();
myLV.load("total_tracks.txt");
myLV.onLoad = function(success) {
if (success) {
playMusicFunc();
}
}
// --------- [Next Track / Previous Track]--------- \\
this.nextTrack.onRelease = function() {
if (curTrackNum < (myLV.totalTracks - 1)) {
curTrackNum++;
playMusicFunc();
}
}

this.prevTrack.onRelease = function() {
if (curTrackNum > 0) {
curTrackNum--;
playMusicFunc();
}
}

kglad
4/3/2006 2:25:21 AM
for you volume knob, you'll have an equation that will determine the volume of
mySound(). when the knob is at one extreme the volume will be zero and at the
other the volume will be 100:

vol=a*knob_position+b
mySound(vol); // where a and b are determined by:

0=a*oneExtreme+b
100=a*otherExtreme+b

Broose
4/3/2006 2:48:18 AM
Here is a revised .fla got the slider working but need to make the
pause/play button swap when clicked on?

var musicFolderName:String = "Music/";
var curTrackNum:Number = 0;
var curPlaybackPos:Number;
var mySound:Sound;
var trackInfoArray:Array;
var trackInfoTracker:Number = 0;
var infoChangerInterv:Number;

_root.volume = 85

this.onEnterFrame=function() {
ratio.text=mySlider.ratio;
mySound.setVolume(_root.volume);
}

function playMusicFunc() {
mySound = new Sound();
mySound.loadSound((musicFolderName + "song" + curTrackNum + ".mp3") ,
true);

mySound.onID3 = function() {
trackInfoArray = new Array();

trackInfoArray[0] = "Track : " + mySound.id3.TIT2;
trackInfoArray[1] = "Track " + (curTrackNum + 1) + " of " +
myLV.totalTracks;

clearInterval(infoChangerInterv);
infoChangerInterv = setInterval(infoChanger, 5000);
infoChanger();
}


if (curTrackNum == (myLV.totalTracks - 1)) {
nextTrack.enabled = false;
nextTrack._alpha = 50;
} else {
nextTrack.enabled = true;
nextTrack._alpha = 100;

}
if (curTrackNum == 0) {
prevTrack.enabled = false;
prevtrack._alpha = 50;
} else {
prevTrack.enabled = true;
prevTrack._alpha = 100;
}

}

function infoChanger() {
trackInfo.text = trackInfoArray[trackInfoTracker];

if (trackInfoTracker == (trackInfoArray.length - 1)) {
trackInfoTracker = 0;
} else {
trackInfoTracker++;
}


}

var myLV:LoadVars = new LoadVars();
myLV.load("total_tracks.txt");
myLV.onLoad = function(success) {
if (success) {
playMusicFunc();
}
}
// --------- [Next Track / Previous Track]--------- \\
this.nextTrack.onRelease = function() {
if (curTrackNum < (myLV.totalTracks - 1)) {
curTrackNum++;
playMusicFunc();
}
}

this.prevTrack.onRelease = function() {
if (curTrackNum > 0) {
curTrackNum--;
playMusicFunc();
}
}


// --------- [/Next Track / Previous Track]--------- \\

// --------------[/play/pause]--------------- \\

this.pauseMusic.onRelease = function() {
curPlaybackPos = mySound.position;
mySound.stop();
disablePause();
}


this.playMusic.onRelease = function() {
mySound.start((curPlaybackPos/1000), 9999);
disablePlay();

}

function disablePlay() {
playMusic.enabled = false;
playMusic._alpha = 0;
pauseMusic.enabled = true;
pauseMusic._alpha = 100;

}

function disablePause() {
playMusic.enabled = true;
playMusic._alpha = 100;
pauseMusic.enabled = false;
pauseMusic._alpha = 0;

}

[quoted text, click to view]

Broose
4/3/2006 11:51:17 AM
I have the songs already starting to play in the action script code. All I
need to do is change the button from the pause to a play button and vise
versa when the user clicks on the button. Below is the action script that I
have that is controlling the whole movie it is on frame one of an action
layer. I also need to know where in the script it will have to go?

Bare with me I am new at Flash. I know how to do all of this in Director but
now we have to do it all in Flash. All your help is GREATLY appreciated.

The buttons are called "playMusic" and "pauseMusic"


var musicFolderName:String = "Music/";
var curTrackNum:Number = 0;
var curPlaybackPos:Number;
var mySound:Sound;
var trackInfoArray:Array;
var trackInfoTracker:Number = 0;
var infoChangerInterv:Number;

_root.volume = 85

this.onEnterFrame=function() {
ratio.text=mySlider.ratio;
mySound.setVolume(_root.volume);
}

function playMusicFunc() {
mySound = new Sound();
mySound.loadSound((musicFolderName + "song" + curTrackNum + ".mp3") ,
true);

mySound.onID3 = function() {
trackInfoArray = new Array();

trackInfoArray[0] = "Track : " + mySound.id3.TIT2;
trackInfoArray[1] = "Track " + (curTrackNum + 1) + " of " +
myLV.totalTracks;

clearInterval(infoChangerInterv);
infoChangerInterv = setInterval(infoChanger, 5000);
infoChanger();
}


if (curTrackNum == (myLV.totalTracks - 1)) {
nextTrack.enabled = false;
nextTrack._alpha = 50;
} else {
nextTrack.enabled = true;
nextTrack._alpha = 100;

}
if (curTrackNum == 0) {
prevTrack.enabled = false;
prevtrack._alpha = 50;
} else {
prevTrack.enabled = true;
prevTrack._alpha = 100;
}

}

function infoChanger() {
trackInfo.text = trackInfoArray[trackInfoTracker];

if (trackInfoTracker == (trackInfoArray.length - 1)) {
trackInfoTracker = 0;
} else {
trackInfoTracker++;
}


}

var myLV:LoadVars = new LoadVars();
myLV.load("total_tracks.txt");
myLV.onLoad = function(success) {
if (success) {
playMusicFunc();
}
}
// --------- [Next Track / Previous Track]--------- \\
this.nextTrack.onRelease = function() {
if (curTrackNum < (myLV.totalTracks - 1)) {
curTrackNum++;
playMusicFunc();
}
}

this.prevTrack.onRelease = function() {
if (curTrackNum > 0) {
curTrackNum--;
playMusicFunc();
}
}


// --------- [/Next Track / Previous Track]--------- \\

// --------------[/play/pause]--------------- \\

this.pauseMusic.onRelease = function() {
curPlaybackPos = mySound.position;
mySound.stop();
disablePause();
}


this.playMusic.onRelease = function() {
mySound.start((curPlaybackPos/1000), 9999);
disablePlay();

}

function disablePlay() {
playMusic.enabled = false;
playMusic._alpha = 0;
pauseMusic.enabled = true;
pauseMusic._alpha = 100;

}

function disablePause() {
playMusic.enabled = true;
playMusic._alpha = 100;
pauseMusic.enabled = false;
pauseMusic._alpha = 0;

}




[quoted text, click to view]

kglad
4/3/2006 2:49:46 PM
if you want one pause/play button and you want it to start your sound on first
release, replace your code with:


this.playToggleBtn.onRelease = function() {
if(!this.toggle){
if(!curPlaybackPos){
curPlaybackPos=0;
}
mySound.start((curPlaybackPos/1000), 9999);
} else {
curPlaybackPos = mySound.position;
mySound.stop();
}
this.toggle=!this.toggle;
}
}
kglad
4/4/2006 3:49:23 AM
i'm not sure what it is about your code that you don't like. in your first
message you indicated you wanted a play/pause toggle. but that's not what you
apparently want.

if you want only one button to be visible at any one time, just use the
following in place of your pause play code:



this.playMusic._visible=0;
this.pauseMusic.onRelease = function() {
curPlaybackPos = mySound.position;
mySound.stop();
this._visible=0;
this._parent.playMusic._visible=1;
};
this.playMusic.onRelease = function() {
mySound.start((curPlaybackPos/1000), 9999);
this._visible=0;
this._parent.pauseMusic._visible=1;
};
Invisiblilez
4/11/2006 8:34:38 PM
I have problems with controlling the volume of the signal of the microphono
somebody could help me I cosay that I have is

getmic_btn.onRelease = function () {
var myMic = Microphone.get();
_root.attachAudio(myMic);
myMic.setUseEchoSuppression(true);


// volumen
myMic.setGain (50);
myMic.start (0, 99);
myMic.activityLevel (100);
//slider.sliderBar._y = -100;
slider.sliderBar.onPress = function () {
startDrag (this, false, this._x, -75, this._x, 0);
};
slider.sliderBar.onReleaseOutside = function () {
stopDrag();
};
slider.sliderBar.onEnterFrame = function () {
_root.setVolume ( 100 - this._y );
};

//DESAPARECE SETTINGS
myMic.onStatus = function (info) {
if (info.code == "Microphone.Muted") {
settings_btn._visible = true;
trace ( "tengo que mostrar el boton ")
}
else if (info.code == "Microphone.Unmuted") {
settings_btn._visible = false;
}
}
stop();
};
kglad
4/12/2006 1:31:41 AM
you're setting the volume of your _root timeline to something between 175 and
100. i think you want to setGain of your mic object (myMic). for example:



slider.sliderBar.onEnterFrame = function () {
myMic.setGain (75+this._y);
};
AddThis Social Bookmark Button