Hi
Could someone please help with this issue. I have made an MP3 player with flash CS3 using AS3. It works fine, but I have created two dynamic text boxes that I want to show the time in minuets and seconds and how long the track will be in minuets and seconds, so that the user can see how far into the track they are and how long the track is.
I was kindly given some code from Kreviii on this forum, which is below:
function convertSecondsToString(n:Number):String {
var rawMin:Number=n/60;
var remain:Number=rawMin%1;
var remainSec:Number=60*remain;
var outMin:String=""+Math.floor(rawMin);
var outSec:String=""+Math.floor(remainSec);
if (parseInt(outMin)<10) {
outMin=“0”+outMin;
}
if (parseInt(outSec)<10) {
outSec=“0”+outSec;
}
var outpustStr=outMin+":"+outSec;
return outpustStr;
}
(Thanks Kreviii)
However, I have made the two dynamic text boxes to accept the output from this code on my mp3 player and I don’t know how to connect this code to those text boxes to accept the output.
Could someone please help. If it helps below is the full script to my MP3 player. Where would be the best place to put the above script, with the code to link the text boxes?
var songList:Array = new Array(“1.mp3”, “2.mp3”, “3.mp3”);
var isPlaying:Boolean = false;
var currentSong:Number = 0;
var song:Sound;
var channel:SoundChannel = new SoundChannel();
var xform:SoundTransform = new SoundTransform();
seekKnob.buttonMode = true;
seekKnob.addEventListener(MouseEvent.MOUSE_DOWN, seekStartDrag);
btnPrev.addEventListener(MouseEvent.CLICK, prevHandler);
btnPause.addEventListener(MouseEvent.CLICK, pauseHandler);
btnPlay.addEventListener(MouseEvent.CLICK, playHandler);
btnNext.addEventListener(MouseEvent.CLICK, nextHandler);
volumeKnob.buttonMode = true;
volumeKnob.addEventListener(MouseEvent.MOUSE_DOWN, volumeStartDrag);
function prevHandler(evt:MouseEvent):void {
prevSong();
}
function pauseHandler(evt:MouseEvent):void {
pauseSong();
}
function playHandler(evt:MouseEvent):void {
playSong(channel.position);
}
function nextHandler(evt:MouseEvent):void {
nextSong();
}
function id3Handler(evt:Event):void {
songInfo.text = song.id3.artist + ": " + song.id3.songName;
}
function soundCompleteHandler(evt:Event):void {
pauseSong();
nextSong();
}
loadSong(songList[currentSong]);
function loadSong(thisSong:String):void {
song = new Sound();
song.load(new URLRequest(thisSong));
song.addEventListener(Event.ID3, id3Handler);
playSong(0);
}
function playSong(position:Number):void {
if (!isPlaying) {
isPlaying = true;
channel = song.play(position);
channel.soundTransform = xform;
channel.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
seekKnob.addEventListener(Event.ENTER_FRAME, seekKnobUpdate);
}
}
function pauseSong():void {
seekKnob.removeEventListener(Event.ENTER_FRAME, seekKnobUpdate);
channel.stop();
isPlaying = false;
}
function prevSong():void {
if (currentSong > 0) {
currentSong–;
pauseSong();
loadSong(songList[currentSong]);
}
}
function nextSong():void {
if (currentSong < songList.length - 1) {
currentSong++;
pauseSong();
loadSong(songList[currentSong]);
}
}
function seekStartDrag(evt:MouseEvent):void {
pauseSong();
seekKnob.startDrag(true, new Rectangle(seekSlider.x, seekSlider.y + seekSlider.height/2, seekSlider.width, 0));
stage.addEventListener(MouseEvent.MOUSE_UP, seekStopDrag);
}
function seekStopDrag(evt:MouseEvent):void {
seekKnob.stopDrag();
playSong(song.length * (seekKnob.x - seekSlider.x) /seekSlider.width);
stage.removeEventListener(MouseEvent.MOUSE_UP, seekStopDrag);
}
function seekKnobUpdate(evt:Event):void {
var pos:Number = seekSlider.width * channel.position / song.length;
if (!isNaN(pos)) {
seekKnob.x = seekSlider.x + pos;
} else {
seekKnob.x = seekSlider.x;
}
}
function volumeStartDrag(evt:MouseEvent):void {
volumeKnob.startDrag(true, new Rectangle(volumeSlider.x, volumeSlider.y + volumeSlider.height/2, volumeSlider.width, 0));
volumeKnob.addEventListener(MouseEvent.MOUSE_MOVE, volumeUpdate);
stage.addEventListener(MouseEvent.MOUSE_UP, volumeStopDrag);
}
function volumeStopDrag(evt:MouseEvent):void {
volumeKnob.removeEventListener(MouseEvent.MOUSE_MOVE, volumeUpdate);
volumeKnob.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP, volumeStopDrag);
}
function volumeUpdate(evt:MouseEvent):void {
xform.volume = (volumeKnob.x - volumeSlider.x) / volumeSlider.width;
channel.soundTransform = xform;
}