I am trying to make a song position slider, ala most media players, which will slowly slide along as the song progresses, but also allows me to drag and drop it to change the position of the song. I have some code which works perfectly in regards to the progress and dragging parts but the song doesn’t change position and the bar reverts to the pre-drag position when I drop it.
// Sound
sneaker = new Sound();
sneaker.attachSound("sneakersong");
sneaker.start(0, 0);
// Song control functions
function resumesong() {
sneaker.resumepos = sneaker.resumepos_ms/1000;
sneaker.start(sneaker.resumepos, 0);
}
// Bar dragging functions
function startdrag() {
posbar.drag = true;
}
function stopdrag() {
posbar.dropped = true;
posbar.drag = false;
}
function changepos() {
if (posbar._xmouse>=0 and posbar._xmouse<=200) {
posbar.bar2._x = posbar._xmouse;
}
}
posbar.onPress = startdrag;
posbar.onRelease = stopdrag;
posbar.onReleaseOutside = stopdrag;
onEnterFrame = function () {
if (posbar.drag) {
changepos();
} else if (posbar.dropped) {
sneaker.resumepos_ms = (posbar.bar2._x/2)*sneaker.duration;
resumesong();
posbar.dropped = false;
} else {
posbar.bar2._x = ((sneaker.position/sneaker.duration)*100)*2;
}
};
FLA attached… I had to take the MP3 out since the software won’t let me upload that size file, but you can add any sound and set its AS Linkage name to ‘sneakersong’.
Useful responses by later tonight or tomorrow would be greatly appreciated as I am becoming dangerously close to my coursework deadline…