Hey everyone, well here’s my situation. I have this mp3 player that I am loading as an external swf in to a container. At first the mp3 player was loading but was not functioning at all. So some code was changed and the mp3 player worked. But when the code was changed the Scrubber bar and volume bar started messing up. Whenever they are clicked, they do not unclick. They just follow your mouse back and forth until you exit the page. I have tried to mess around with it and I can’t figure out what needs to be changed or added to make this work correctly. Any Help or pointers would be greatly appreciated
Here is the original code that needed to be changed to make it work
Original Code
//constructor
public function Mp3PlayerAA()
{
this.visible = false;
loadXmlFile(stage.loaderInfo.parameters.xmlFile || "mp3player.xml");
}
This is what I added to make it load correctly. I had someone help me with this.
//constructor
public function Mp3PlayerAA()
{
this.visible = false;
this.addEventListener(Event.ADDED_TO_STAGE, stageChecker);
} private function stageChecker(e:Event):void
{ loadXmlFile(parent.stage.loaderInfo.parameters.xmlFile || "mp3player.xml");
this.removeEventListener(Event.ADDED_TO_STAGE, stageChecker);
}
Now here is the code for the Scrubber bar and the Volume bar. Maybe someone can help me with what is happening here.
//handler for volumeButton mouse down event
private function volumeButton_mouseDownHandler(e:Event):void
{
volumeDrag = true;
if (volumeButton.hitTestPoint(stage.mouseX, stage.mouseY, true)) {
dx = this.mouseX - volumeButton.x;
} else {
dx = Math.round(volumeButton.width / 2);
}
stage.addEventListener(MouseEvent.MOUSE_MOVE, stage_mouseMoveHandler);
updateVolumeButtonX(this.mouseX + dx);
}
//handler for playBarButton mouse down event
private function playBarButton_mouseDownHandler(e:Event):void
{
myPlayer.removeEventListener(PlaybackEvent.PLAYBACK_TIME_UPDATE, myPlayer_timeUpdate);
playDrag = true;
if (playBarButton.hitTestPoint(stage.mouseX, stage.mouseY, true)) {
dx = this.mouseX - playBarButton.x;
} else {
dx = Math.round(playBarButton.width / 2);
}
stage.addEventListener(MouseEvent.MOUSE_MOVE, stage_mouseMoveHandler);
updatePlayBarButtonX(this.mouseX + dx);
}
//handler for the mouse move event
private function stage_mouseMoveHandler(event:MouseEvent):void {
if (volumeDrag) { updateVolumeButtonX(this.mouseX + dx) }
if (playDrag) { updatePlayBarButtonX(this.mouseX + dx) }
event.updateAfterEvent();
}
//handler for the stage mouse up event
private function stage_mouseUpHandler(event:MouseEvent) {
if (playDrag) {
myPlayer.addEventListener(PlaybackEvent.PLAYBACK_TIME_UPDATE, myPlayer_timeUpdate);
var seekTime:Number = (playBarButton.x - playBarShape.x - playBarButton.width) / playRatio;
myPlayer.seek(seekTime / myPlayer.totalTime);
playDrag = false;
}
if (volumeDrag) {volumeDrag = false;}
stage.removeEventListener(MouseEvent.MOUSE_MOVE, stage_mouseMoveHandler);
}
//update volume button pusition
private function updateVolumeButtonX(sx:Number):void {
sx = Math.max(volumeBar.x + volumeButton.width, Math.min(volumeBar.x+volumeBar.width - volumeButton.width, sx));
if (sBtnX != sx) {
sBtnX = sx;
volumeButton.x = Math.round(sBtnX);
moveVolumeButtonHandler();
}
}
//update playbar button position
private function updatePlayBarButtonX(sx:Number):void
{
sx = Math.round(Math.max(playBarShape.x + playBarButton.width, Math.min(playBarShape.x+playBarShape.width - playBarButton.width, sx)));
if (sBtnX != sx) {
sBtnX = sx;
playBarButton.x = Math.round(sBtnX);
movePlayBarButtonHandler();
}
}
//move the volume button
private function moveVolumeButtonHandler():void
{
volumeTrack.width = volumeButton.x - volumeBar.x - volumeButton.width;
myPlayer.volume = (volumeButton.x - volumeBar.x - volumeButton.width ) / volRatio;
if (muteFlag) { muteFlag = false;}
}
//handler for the move playbar button event
private function movePlayBarButtonHandler():void
{
playBarTrack.width = playBarButton.x - playBarShape.x - playBarButton.width;
}
//initialize player track
private function resetPlayerTrack():void
{
playBarButton.x = playBarShape.x+playBarButton.width;
movePlayBarButtonHandler();
}
//handler for volumeBar click event
private function onVolumeBar_ClickHandler(e:Event):void
{
volumeButton.x = volumeBar.x + volumeBar.mouseX-volumeButton.width;
volumeTrack.width = volumeButton.x - volumeBar.x - volumeButton.width;
myPlayer.volume = (volumeButton.x - volumeBar.x - volumeButton.width ) / volRatio;
if (muteFlag) { muteFlag = false;}
}
//handler for playBarShape click event
private function onPlayBarShape_ClickHandler(e:Event):void
{
playDrag = true;
playBarButton.x = playBarShape.x+playBarShape.mouseX-playBarButton.width;
movePlayBarButtonHandler();
var seekTime:Number = (playBarButton.x - playBarShape.x - playBarButton.width) / playRatio;
myPlayer.seek(seekTime/myPlayer.totalTime);
}
//handler for volumeTrack click event
private function onVolumeBar_MouseDownHandler(e:Event):void
{
volumeButton.x = volumeTrack.x+volumeTrack.mouseX;
volumeTrack.width = volumeButton.x - volumeBar.x - volumeButton.width;
myPlayer.volume = (volumeButton.x - volumeButton.width - volumeBar.x) * volRatio / 2;
volumeDrag = true;
if (volumeButton.hitTestPoint(stage.mouseX, stage.mouseY, true)) {
dx = this.mouseX - volumeButton.x;
} else {
dx = Math.round(volumeButton.width / 2);
}
stage.addEventListener(MouseEvent.MOUSE_MOVE, stage_mouseMoveHandler);
updateVolumeButtonX(this.mouseX + dx);
}
//handler for playBarTrack click event
private function onPlayBarShape_MouseDownHandler(e:Event):void
{
myPlayer.removeEventListener(PlaybackEvent.PLAYBACK_TIME_UPDATE, myPlayer_timeUpdate);
playBarButton.x = playBarTrack.x + playBarTrack.mouseX;
playDrag = true;
if (playBarButton.hitTestPoint(stage.mouseX, stage.mouseY, true)) {
dx = this.mouseX - playBarButton.x;
} else {
dx = Math.round(playBarButton.width / 2);
}
stage.addEventListener(MouseEvent.MOUSE_MOVE, stage_mouseMoveHandler);
updatePlayBarButtonX(this.mouseX + dx);
}
}
}