PDA

View Full Version : Simple mp3 player


maximusprime
01-24-2003, 10:36 PM
ok guys, this should be pretty easy.

i have a sound.swf file with the following functions:

function startSound(){
mysoundobj=new Sound(this)
mysoundobj.attachSound("feelGood")
mysoundobj.start()
}
function stopSound(){
mysoundobj.attachSound("feelGood")
mysoundobj.stop()
}

where feelGood is the linkage export id of the sound.

now, i have a simple main movie with 2 buttons, stop and play. when you hit play, it forwards to frame 2, which contains a movie symbol, with the following scripting:

onClipEvent(load){
loadMovieNum("sound.swf",1)
}
var initialized
onClipEvent(enterFrame){
percentloaded=Math.floor(_level1.getBytesLoaded()/_level1.getBytesTotal()*100)
if(percentloaded == 100 && !initialized){
_level1.startSound()
initialized=true
_visible=false
}
}

this starts the load process, and the sound downloads. when it reaches 100 percent, it starts playing and the load animation is set to invisible, so the song name located underneath is shown.

The stop button has the following code:
on(release){
_level1.stopSound()
_root.gotoAndPlay(1)
}
so it invokes the stopsound method and goes back to frame one.

the problem, as some of you will have spotted already, is that to prevent the song from starting playing every time the song name animation loops, i had to add an "initialize" variable, so it only starts play once. however, this variable remains true even after the stop button is hit. my question is, when the stop button is hit, how do i set the initalization back to false? im not too familiar, with aS syntax, but i assume it is something simple like (clipname).initialize=false or something like that, but i cant get it working.

suggestions?

Billy T
01-27-2003, 04:46 AM
I would have thought that would given you a syntax error. the line

var initialized

should be inside a clip event handler (eg load)

also, your stop sound function can just be

function stopSound(){
mysoundobj.stop()
}

try this

on frame 2 of _root (which you should refer to as _level0 as you are loading movies into levels), put this

initialized =false;

an then on your mc put this

onClipEvent(load){
loadMovieNum("sound.swf",1)
}
onClipEvent(enterFrame){
percentloaded=Math.floor(_level1.getBytesLoaded()/_level1.getBytesTotal()*100)
if(percentloaded == 100 && !initialized){
_level1.startSound()
_parent.initialized=true
_visible=false
}
}

and on the stop button put

on(release){
_level1.stopSound()
_level0.gotoAndStop(1)
}

see how that goes

cheers