I am working with AS3 to build a very simple mp3 player on my site. So far the play and pause button work fine, but when I try to move the slider then click the pause button, it doesn’t pause, and then clicking the play button again causes it to play a new file.
I’m assuming that for some reason when I call the playMp3 function from my MouseEvent, it’s within an object or something and not at the root, so it’s like loading a new sound file, but I don’t know how to fix that.
Here is my code, any other suggestions about my code are welcome, I’m a noob at this and always looking for a better way to do things:
looks like your problem is caused by MOUSE_UP event.
On pickupSlider function you add:
parent.addEventListener(MouseEvent.MOUSE_UP, dropSlider);
but on dropSlider function you only remove listener for MOUSE_MOVE so MOUSE_UP will keep caling dropSlider function. If you’ll add:
parent.removeEventListener(MouseEvent.MOUSE_UP, dropSlider);
in your dropSlider function it should be working fine.
//TIP
You don’t have to add CLICK listener each time in playMp3 and pauseMp3 function if you never remove them. You can add both of them at start and keep adding/removing buttons when needed (or use .visible true/false instead). Listeners are still attached to objects even if they are removed from stage. It’s importatnt, because if someday U’ll want to remove object and leave listeners to it garbage collector won’t take it and U’ll have memory leaks.