• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How do you remove a movie clip from the stage via a dispatch event?

Engaged ,
May 01, 2012 May 01, 2012

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?

TOPICS
ActionScript

Views

684

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 01, 2012 May 01, 2012

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

...

Votes

Translate

Translate
LEGEND ,
May 01, 2012 May 01, 2012

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

Thanks.

I assigned the event listener to myPlayCredits.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

LATEST

You're welcome

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines