I am not new to programming but I decided to learn Flash for fun this summer. I have a program that is printing Circles as children and I want it so when the user hovers over a certain circle it will remove that child. Pseudo code in case you don't get what I'm saying:
if ( mouse.x = onCircle && mouse.y = onCircle){
removeChild(thatCircle);
}
The problem is I don't know how to find what that specific child is and how to remove it.
here is my code so far:
//Import
import flash.utils.*;
//Vars
var circle:Shape = new Shape(); // The instance name circle is created
var alive;
alive = "true";
var challange;
challange = 1;
var ogtimer = setInterval(showCircle,1000*challange);
var circlesOnScreen: int;
circlesOnScreen = 0;
var cycles : int;
cycles = 0;
var base : int;
base = 0;
function showCircle(){
if (circlesOnScreen < 14){
//Variables
var ranX:Number = Math.ceil(Math.random()*475);
var ranY:Number = Math.ceil(Math.random()*790);
var circleSpriteVar:circleSprite = new circleSprite();
addChild(circleSpriteVar);
circleSpriteVar.x = ranX;
circleSpriteVar.y = ranY;
circlesOnScreen = circlesOnScreen + 1;
cycles = cycles + 1;
/*if (mouseisover circle){
circle.removeChildAt(0)
}*/
if (cycles > 3){
base = cycles * 1.15
challange = base / 10
}
}else{
gotoAndStop(3)
}
}
EDIT: Please correct your title or your description. Title says Mouse click and description says hover. These are different things.
You would need to add a MOUSE_OVER mouse listener to each of your circles and it will fire each time you hover the mouse over the circle. Then remove the circle over which the mouse is. Here's sample code (assuming Circle is a Sprite):
circle.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver,false,0,true);
protected function onMouseOver(event:MouseEvent):void
{
var circle:Sprite = event.currentTarget as Sprite;
circle.removeEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
removeChild(circle);
}
Hope this answers your question. Please accept the answer if it does, or let me know if you need more information. Thanks.