looping sound problem
i have this code
when i run it ; it plays only one time
its background music and i need to play it ina loop
what i need to add to my code?
thank you
my code:
import flash.media.SoundChannel;
import flash.events.MouseEvent;
import flash.events.Event;
var isPlaying:Boolean = true;
var lastposition:Number = 0;
var mysound:mew = new mew();
var soundchannel:SoundChannel = new SoundChannel();//So now that we can play the sound, how do we stop it? You can NOT stop the sound using the Sound class (e.g. mysound.stop(); will not work). Another class is used for that - the SoundChannel class - which has a stop() method that will let you stop a sound's playback.
soundchannel = mysound.play(0,0);// playing sound in the channel
soundchannel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete1);
function onPlaybackComplete1(event:Event):void
{
lastposition = 0;
soundchannel.stop();
btn.btn_pause.visible = false;
trace("finished");
isPlaying=false;
}
btn.addEventListener(MouseEvent.CLICK, playsound);
function playsound(event:MouseEvent):void
{
if (! isPlaying)
{
soundchannel = mysound.play(lastposition,0);
btn.btn_pause.visible = true;
isPlaying = true;
soundchannel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete1);
}
else
{
lastposition = soundchannel.position;
soundchannel.stop();
btn.btn_pause.visible = false;
/*trace(lastposition.toFixed(0), mysound.length.toFixed(0));*/
isPlaying = false;
}
soundchannel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
function onPlaybackComplete(event:Event):void
{
lastposition = 0;
soundchannel.stop();
btn.btn_pause.visible = false;
trace("finished");
isPlaying=false;
soundchannel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
}
}