Skip navigation
Currently Being Moderated

Remove Child and Event.SOUND_COMPLETE not working inside movie clip. What's the problem?

May 30, 2012 9:56 AM

Tags: #movieclip #sound_complete

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?

 
Replies
  • kglad
    61,990 posts
    Jul 21, 2002
    Currently Being Moderated
    May 30, 2012 1:43 PM   in reply to QuigleyMcCormick

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    May 31, 2012 3:43 AM   in reply to QuigleyMcCormick

    Hi,

     

    Your code is bit messy, Please organize your code in a class, so that everyone can easily understand your code. And your problem is very simple, just make a structure, your query will automatically resolved, because the ligoc is quite good.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points