I have a movie clip that is called to the stage. The user then clicks a button and music plays. As the music starts, another movie clip is called, a simulation of an equilizer. There are several things that should happen:
1) When the user closes the movie clip the music is supposed to stop playing and the equilizer movie clip is removed. What actually happens is the music stops playing but the equilzer movie clip is not removed.
2) When the music is finished playing the equilzer is supposed to be removed from the stage and the play button is reactivated. But none of that happens. When I click on the movie clip a second time equilizer is still there and the play button is not reactivated.
Here's the code that calls the movie clip to the stage.
stage.addEventListener(MouseEvent.MOUSE_DOWN, goButtons);
function goButtons(event:MouseEvent):void
{
if (event.target == Song_bnt)
{
SoundMixer.stopAll();
addChild(myPlaySong);
myPlaySong.x = 304;
myPlaySong.y = 105;
//event.stopImmediatePropagation();
}
Here's the code in the movie clip:
import flash.media.Sound;
import flash.events.Event;
stop();
var playRayJaySong:RJSong;
var playRayJaySongChannel:SoundChannel;
var equilizer:Equilizer;
equilizer = new Equilizer();
playRayJaySong = new RJSong();
//Plays music, inactivates buttons, and adds the equilizer to the stage.
PlaySongRJClip.addEventListener(MouseEvent.MOUSE_DOWN, songPageButton);
function songPageButton(event:Event):void
{
playRayJaySongChannel = playRayJaySong.play();
PlaySongRJClip.visible = false;
ClicktoPlaySong.visible = false;
addChild(equilizer);
equilizer.x = 269;
equilizer.y = 246;
}
//Removes the equilizer from the stage when the music is complete.
PlaySongRJClip.addEventListener(Event.SOUND_COMPLETE, rjSoundComplete);
function rjSoundComplete(e:Event):void
{
PlaySongRJClip.visible = true;
ClicktoPlaySong.visible = true;
removeChild(equilizer);
}
//Removes the equilizer and event listeners from stage and calls dispatch event to close the movie clip.
closeSong_bnt.addEventListener(MouseEvent.MOUSE_DOWN, CloseSong);
function CloseSong(event:MouseEvent):void
{
removeChild(equilizer);
dispatchEvent(new Event("RemoveMSong"));
PlaySongRJClip.removeEventListener(MouseEvent.MOUSE_DOWN, songPageButton);
PlaySongRJClip.removeEventListener(Event.SOUND_COMPLETE, rjSoundComplete);
}
//Removes the MovieClip from the stage when the user clicks on the close button inside the MovieClip.
myPlaySong.addEventListener("RemoveMSong", RemoveSongClip);
function RemoveSongClip(e:Event):void
{
SoundMixer.stopAll();
removeChild(myPlaySong);
}
Any thoughts?
that's not well organized which is suspect is the problem. you should have all your code on one frame of one timeline or, better, in class files so it's easy to see what you're doing and easy to debug your code.
to start, it looks like the movieclip that contains that code is dispatching "RemoveMSong" and it looks like myPlaySong is listening for that event. unless those two movieclips are the same, that won't work.
Thanks everyone. I am fairly new to action script and have not used class files at this point. I will try to reorganize into a class file.
In the mean time I do have a question. What would be the most efficient way to communicate, from the main time, to button inside of a movieclip? For example, the user clicks a button and a movie clip is added to the stage. This movie clip also has a button that would close and remove it from the stage. Currently I am using a dispatch event from within the movie clip. In other words my code for this action is inside the movie clip instead of on the main timeline.
This bit of code is inside of the movie clip, not on the main timeline.
closeSong_bnt.addEventListener(MouseEvent.MOUSE_DOWN, CloseSong);
function CloseSong(event:MouseEvent):void
{
removeChild(equilizer);
dispatchEvent(new Event("RemoveMSong"));
PlaySongRJClip.removeEventListener(MouseEvent.MOUSE_DOWN, songPageButton);
PlaySongRJClip.removeEventListener(Event.SOUND_COMPLETE, rjSoundComplete);
}
Is there a more efficient way to communicate with the "closeSong_bnt" button using code on the main timeline?
I figured out the problem. Here's how I reorganized the code (all in one frame).
//Code for Ray Jay song.
var playRayJaySong:RJSong;
var playRayJaySongChannel:SoundChannel;
playRayJaySong = new RJSong();
myPlaySong.equilizer_inst.visible = false;
//Plays the song.
myPlaySong.PlaySongRJClip.addEventListener(MouseEvent.MOUSE_DOWN, songPageButton);
function songPageButton(event:Event):void
{
playRayJaySongChannel = playRayJaySong.play();
playRayJaySongChannel.addEventListener(Event.SOUND_COMPLETE, rjSoundComplete);
myPlaySong.equilizer_inst.visible = true;
myPlaySong.PlaySongRJClip.visible = false;
myPlaySong.ClicktoPlaySong.visible = false;
}
//Removes the MovieClip from the stage when the user clicks on the close button inside the MovieClip.
myPlaySong.closeSong_bnt.addEventListener(MouseEvent.CLICK,RemoveSongC lip);
function RemoveSongClip(e:Event):void
{
SoundMixer.stopAll();
removeChild(myPlaySong);
myPlaySong.equilizer_inst.visible = false;
myPlaySong.PlaySongRJClip.visible = true;
myPlaySong.ClicktoPlaySong.visible = true;
playRayJaySongChannel.removeEventListener(Event.SOUND_COMPLETE, rjSoundComplete);
}
//Resets all of the movieclips to their orginal state.
function rjSoundComplete(e:Event):void
{
myPlaySong.equilizer_inst.visible = false;
myPlaySong.PlaySongRJClip.visible = true;
myPlaySong.ClicktoPlaySong.visible = true;
}
Thanks all for your suggests and input.
North America
Europe, Middle East and Africa
Asia Pacific