Copy link to clipboard
Copied
I have a movie clip that is added to the stage. There is a close button on that movie clip that I would like to close and remove the clip from the stage. But the close button does not work when it is clicked, nothing happens.
Here's the flow along with the code:
//Adds the movie clip to the stage
var myPlayCredits:mc_playCredits = new mc_playCredits();
stage.addEventListener(MouseEvent.MOUSE_DOWN, goButtons);
function goButtons(event:MouseEvent):void
{
if (event.target == Credits_bnt)
{
SoundMixer.stopAll();
addChild(myPlayCredits);
myPlayCredits.x = 511;
myPlayCredits.y = 386;
}
//This is the code on the button inside the movie clip that calls the dispatch
import flash.events.Event;
stop();
closeCredit.addEventListener(MouseEvent.MOUSE_DOWN, closeCreditPopupScreen);
function closeCreditPopupScreen (event:MouseEvent):void
{
dispatchEvent(new Event("RemoveMCcredit"));
}
//Removes (is supposed to remove) the MovieClip from the stage when the user clicks on the close button inside the MovieClip.
stage.addEventListener("RemoveMCcredit", RemoveCreditClip);
function RemoveCreditClip(e:Event):void
{
removeChild(myPlayCredits);
}
Anybody have any thoughts?
Why don't you just assign the event listener to the closeCredit button after you instantiate myPlayCredits and just have the event listener call the RemoveCreditClip function directly...
var myPlayCredits:mc_playCredits = new mc_playCredits();
myPlayCredits.loseCredit.addEventListener(MouseEvent.CLICK, RemoveCreditClip);\
If you want to use the dispatch event approach, try assigning the listener to the myPlayCredits mc, not the stage. (Or set the Event's bubbling argument to true if you assign it t
...Copy link to clipboard
Copied
Why don't you just assign the event listener to the closeCredit button after you instantiate myPlayCredits and just have the event listener call the RemoveCreditClip function directly...
var myPlayCredits:mc_playCredits = new mc_playCredits();
myPlayCredits.loseCredit.addEventListener(MouseEvent.CLICK, RemoveCreditClip);\
If you want to use the dispatch event approach, try assigning the listener to the myPlayCredits mc, not the stage. (Or set the Event's bubbling argument to true if you assign it to the stage)
Copy link to clipboard
Copied
Thanks.
I assigned the event listener to myPlayCredits.
Copy link to clipboard
Copied
You're welcome