Skip to main content
November 5, 2014
Question

Removing a MovieClip by Clicking

  • November 5, 2014
  • 1 reply
  • 401 views

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 ?

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
November 5, 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
}
November 5, 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 ?

kglad
Community Expert
Community Expert
November 5, 2014

what's line 937?