HI,
I am trying to make a sound seek bat, which works fine the only problem is that when i press and release aka(MOUSE_DOWN , MOUSE_UP), the sound plays again and again , so after few click i can hear same music playing at several different time
var _soundurl:String = "music.mp3";
var _sound:Sound = new Sound();
var _channel:SoundChannel;
var _position:Number;
var _rectangle:Rectangle;
_sound.addEventListener(Event.COMPLETE, loadComplete);
_sound.load(new URLRequest(_soundurl));
function loadComplete(eve:Event):void
{
_channel = new SoundChannel();
_channel = _sound.play();
_channel.addEventListener(Event.SOUND_COMPLETE, soundComplete);
_rectangle = new Rectangle(0,0,seek_mc.bar_mc.width,0);
seek_mc.addEventListener(Event.ENTER_FRAME, doEnterFrame);
}
function soundComplete(eve:Event):void
{
_channel = _sound.play();
}
seek_mc.seeker_mc.addEventListener(MouseEvent.MOUSE_UP, doMouseUp);
stage.addEventListener(MouseEvent.MOUSE_UP, doMouseUp);
seek_mc.seeker_mc.addEventListener(MouseEvent.MOUSE_DOWN, doMouseDown);
function doEnterFrame(eve:Event):void
{
var _soundpercent:Number = _channel.position/_sound.length;
seek_mc.seeker_mc.x = _soundpercent * seek_mc.bar_mc.width;
info_txt.htmlText = ""
//trace (_soundpercent * seek_mc.bar_mc.width);
}
function doMouseDown(eve:MouseEvent):void
{
seek_mc.removeEventListener(Event.ENTER_FRAME, doEnterFrame);
seek_mc.seeker_mc.addEventListener(MouseEvent.MOUSE_MOVE, doMouseMove);
seek_mc.seeker_mc.startDrag(false,_rectangle);
_channel.stop();
}
function doMouseUp(eve:MouseEvent):void
{
seek_mc.addEventListener(Event.ENTER_FRAME, doEnterFrame);
seek_mc.seeker_mc.removeEventListener(MouseEvent.MOUSE_MOVE, doMouseMove);
seek_mc.seeker_mc.stopDrag();
_channel = _sound.play(_position);
}
function doMouseMove(eve:MouseEvent):void
{
var _diff:Number = eve.currentTarget.x/seek_mc.bar_mc.width;
_position = _sound.length*_diff;
//info_txt.htmlText = String(_channel.position) + " : " + String(_sound.length);
_channel.stop();
}