Groups | Blog | Home
all groups > flash actionscript > may 2004 >

flash actionscript : displaying minutes and seconds



waveturtle
5/21/2004 8:43:32 PM
I want to display the time a song has been playing in minutes and seconds, but
I'm not quite sure how to go about it... Could someone either direct me to a
tutorial or offer a few scripting ideas?

I know it would involve Sound.position and setting an interval to update the
dynamic text field, other than that, I'm a bit stuck on displaying a minute and
resetting the seconds.

And if I'm using one sound object, how can I reset the sound.position so it
starts over after the a new song loads into the sound object?

here is what I have so far:

http://homepage.mac.com/rob.knight/musicplayer.html

Thank you
Rob
Jack.
5/21/2004 9:39:03 PM
you need a loop to display the time - onEnterFrame
and a boolean variable to trigger the loop - stopped
and a sound object to poll the position of - myMp3

stopped = true; // no track playing

this.onEnterFrame = function(){
if(!stopped){ // only update when = false
mps = int(myMP3.position/1000);
mps<1 ? buff.text="Buffering" : buff.text="";
nmins = Math.floor(mps/60);
nsecs = mps - (nmins*60);
nsecs<10 ? nsecs="0"+nsecs : null;
nmins<10 ? nmins="0"+nmins : null;
mp3pos.text = nmins+" : "+nsecs;
}
};

myMP3.loadSound(Url,true); // load your mp3
stopped = false ; // trigger the loop to update
myMP3.onSoundComplete=function(){
stopped = true; mp3pos.text = ""; // reset loop and textfield
};

hth
AddThis Social Bookmark Button