PDA

View Full Version : MouseOver, mouseOut doesn't work!!



qpixo
November 8th, 2009, 10:10 PM
I'm trying to create a mouseEvent for my 5 points but it's ONLY work on last point. While clicking on the others point the mouseOut and mouseOver doesn't respond, however the ONLY work on last point.

Does anyone can help me?




//Global var
private var pointRepere;

createPoints(5);

private function createPoints(number:int):void
{
var xPos:int = 0;
var yPos:int = 0;

for (var i:int=0; i<number;i++)
{
pointRepere = new PointRepere();
pointRepere.buttonMode = true;
pointRepere.x = xPos;

xPos += i*30 + 50;
pointRepere.y = yPos;
yPos += i*10 + 20;

menu.addChild(pointRepere);

pointRepere.addEventListener(MouseEvent.MOUSE_OVER , handlePointMouseOver);
pointRepere.addEventListener(MouseEvent.MOUSE_OUT, handlePointMouseOut);
}
}


private function handlePointMouseOver(event:MouseEvent):void
{
pointRepere.gotoAndStop('mouseOver');
}


private function handlePointMouseOut(event:MouseEvent):void
{
pointRepere.gotoAndStop('mouseOut');
}

_kp
November 9th, 2009, 02:57 AM
you are assigning a new point to your variable in the loop so you don't have any references of your points but the last one (which is the one that works).

You need to replace pointRepere with e.currentTarget in both your event handlers.