# OnSoundComplete

**URL:** <https://forum.kirupa.com/t/onsoundcomplete/323661>\
**Category:** flash\
**Created:** [July 11, 2011, 5:13pm UTC](https://forum.kirupa.com/t/onsoundcomplete/323661 "2011-07-11T17:13:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![misael1](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@misael1](https://forum.kirupa.com/u/misael1)\
**Post date:** [July 11, 2011, 5:13pm UTC](https://forum.kirupa.com/t/onsoundcomplete/323661/1 "2011-07-11T17:13:46Z")

</div>

Hi! hope sombody helpme…  
i found this as code to make some web, only that hv a problem, when the fisrt song over, it play again, and dont play next,

here`s my code hope sombody could help me to find the error…

class com.oop.media.Music {

var music:Sound;  
var \_on:Boolean;  
var \_loaded:Boolean;  
var file:String;  
var title:String;  
var breakPosition:Number;  
function Music () {  
\_on=false;  
\_loaded=false;  
}

function setVolume (val:Number) {  
music.setVolume(val);  
}

function getVolume () {  
return music.getVolume();  
}

function setPosition (val:Number) {  
breakPosition=val;  
var pre\_on=\_on;  
this.play();  
if (!pre\_on) pause();

}

function percentLoaded () {  
return Math.ceil(getBytesLoaded()/getBytesTotal()\*100);  
}

function getBytesLoaded () {  
return music.getBytesLoaded();  
}

function getBytesTotal() {  
return music.getBytesTotal();  
}

function getPosition () {  
return Math.floor(music.position);  
}

function getMinute () {  
var m=Math.floor((getPosition()/1000)/60);  
return ((m\<10)?“0”+m:m)||“00”;  
}

function getSecond () {  
var s=Math.floor((getPosition()/1000)%60);  
return ((s\<10)?“0”+s:s)||“00”;  
}

function getDuration () {  
return Math.floor(music.duration);  
}

function getMinuteDuration () {  
var m=Math.floor((getDuration()/1000)/60);  
return ((m\<10)?“0”+m:m)||“00”;  
}

function getSecondDuration () {  
var s=Math.floor((getDuration()/1000)%60);  
return ((s\<10)?“0”+s:s)||“00”;  
}

function load (f:String,t:String) {  
close();  
breakPosition=0;  
\_loaded=false;  
file=f;  
title=t;  
if (\_on) stop();  
music[“owner”]=this;  
music.onSoundComplete = function() {  
this[“owner”].stop();  
this[“owner”].play();  
}

music.loadSound(file,true);  
\_on=true;

}

function close () {  
delete(music);  
music=new Sound();  
}

function stop () {  
breakPosition=0;  
this.play();  
music.stop();  
\_on=false;

}

function play () {  
music.start(breakPosition/1000);  
\_on=true;  
}

function pause () {  
breakPosition=getPosition();  
music.stop();  
\_on=false;  
}

}
