Copy link to clipboard
Copied
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 ?
Copy link to clipboard
Copied
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
}
Copy link to clipboard
Copied
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 ?
Copy link to clipboard
Copied
what's line 937?
Copy link to clipboard
Copied
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);
}
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
use the code i suggested,
function close(e:MouseEvent):void
{
removeChild(e.currentTarget);
}
Copy link to clipboard
Copied
you must have something on stage called popcount. use a different name and make sure you declare it:
var popcount:int;
Find more inspiration, events, and resources on the new Adobe Community
Explore Now