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

Removing a MovieClip by Clicking

Guest
Nov 05, 2014 Nov 05, 2014

I want to Remove a Movie Clip loaded from an Array by just Clicking it.

Here is how I loaded them

function load1(Event:MouseEvent):void
{


  addChild(notes[0]);
  notes[0].x = 100;
  notes[0].y = 100;

}

I have three Movie Clips in this Array which are loaded on a condition.

Once one of the MovieClip is on the Screen , I want to remove it by just clicking anywhere on this Movie Clip , How can I do this ?

TOPICS
ActionScript
349
Translate
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
Community Expert ,
Nov 05, 2014 Nov 05, 2014

use:

function load1(Event:MouseEvent):void
{


  addChild(notes[0]);
  notes[0].x = 100;
  notes[0].y = 100;

notes[0].addEventListener(MouseEvent.CLICK,clickF);

}

function clickF(e:MouseEvent):void{
removeChild(e.currentTarget);  // notes[0] still exists though and still has a mouse listener.  if you want to remove it from the notes array and ready it for gc, remove the listener and use the splice() method of arrays
}
Translate
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
Guest
Nov 05, 2014 Nov 05, 2014

Thanks a lot kglad , I really appreciate your help with the code , that really helps as I am really new to AS3.

I tried this but I am getting this Error

//////////////////////////////

Scene 1, Layer 'AS', Frame 2, Line 937, Column 18 1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:DisplayObject.

How do I fix that ?

Translate
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
Community Expert ,
Nov 05, 2014 Nov 05, 2014

what's line 937?

Translate
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
Guest
Nov 05, 2014 Nov 05, 2014

kglad,

Line 937 Contains the Variable that I am incrementing with each Child added on to the stage

popcount ++;

Here is the Whole Function

function load1(Event:MouseEvent):void
{


  addChild(notes[0]);
  notes[0].x = 100;
  notes[0].y = 100;
  popcount ++;
  trace("Counter Value:" + popcount);
  if ( popcount == 2)
   {

    btn_nxt.addEventListener(MouseEvent.CLICK , nextframepop1);
  
  }
 
 
}

Translate
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
Guest
Nov 05, 2014 Nov 05, 2014

Hi ,

I am trying to Remove the Child (correct) from the stage and I am using this Event Listener function close to call this remove action.

if the Answer is Correct , this new Movie Clip name Correct should show up and when clicked , it should move to next Frame, otherwise another Movie Clip Wron Answer should pop up and stay on the same frame.

Here is my Code , but for some reason , its not working

////// CODE ///////

LISTENER /////////

   if(e.currentTarget == rb1){ /// Checking the Radio Button Selection

   score++;  /// Correct Answer will add 1 to Score.

    addChild(correct);     //// THIS IS THE MOVE CLIP I WANT TO SHOW

    correct.x = 296;

    correct.y = 263;

    correct.addEventListener(MouseEvent.CLICK,close); /// INSIDE THIS CALL , I AM ADDING AN EVENT LISTENER TO SEE IF THE MOVIE CLIP IS CLICKED, IF YES , IT SHOULD CALL THE FUNCTION "CLOSE" Mentioned Below.

    trace("Correct Answer");

    trace(score);

   }

/////////////////////////////////////////////

FUNCTION NAME CLOSE

function close(e:MouseEvent):void
   {

   
  
   stage.removeChild(e.target);
  

  
  }

Here is the Error that I get

//// ERROR ///////////

Scene 1, Layer 'AS', Frame 2, Line 962, Column 23 1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:DisplayObject.

Translate
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
Community Expert ,
Nov 06, 2014 Nov 06, 2014
LATEST

use the code i suggested,

function close(e:MouseEvent):void
   {
   removeChild(e.currentTarget);   
  }

Translate
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
Community Expert ,
Nov 06, 2014 Nov 06, 2014

you must have something on stage called popcount.  use a different name and make sure you declare it:

var popcount:int;

Translate
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