Play music after an object drags
Hello all,
I´m trying to do a music player that will start playing music when an object move towards the Y axis.
So basically, I have an object, a circle in this case, that will move only 56 px up and down with a startDrag, what I need is that when the circle is at Y = -56 px (it´s higger position) music starts (Play),
and when the circle is dragged down, music should stop.
At the moment, music plays on every click, the boolean is not working either, so every time I click music overlap.
I past my code in case that helps.
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
/* Arrastrar y colocar
Permite que la instancia del símbolo especificado se pueda mover con una acción de arrastrar y colocar.
*/
var fl_SC:SoundChannel;
var fl_ToPlay:Boolean = true;
vinilo_click_drop.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);
function fl_ClickToDrag(event:MouseEvent):void
{
vinilo_click_drop.startDrag(false, new Rectangle(0,-56,0,56));
if ((vinilo_click_drop.Y !=0) && (fl_ToPlay))
{
var s:Sound = new Sound(new URLRequest("http://www.helpexamples.com/flash/sound/song1.mp3"));
fl_SC = s.play();
}
else if (fl_ToPlay)
{
fl_SC.stop();
}
fl_ToPlay = !fl_ToPlay;
}
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
function fl_ReleaseToDrop(event:MouseEvent):void
{
vinilo_click_drop.stopDrag();
}
Thank you all for the help.