View Full Version : how do you say all except event.target ?
jsaul
06-11-2008, 04:07 PM
Hi,
I have some clips linked to a class, in the class I can call a function with a MouseEvent, I want to add an EventListener to all objects, EXCEPT the event.target.
How do you write this ??
DiamondDog
06-11-2008, 04:50 PM
This might be one way.
I'm assuming your clips are linked to the 'Thing' class.
Add an event listener to all of them, but when the mouse event is despatched do something to all Things EXCEPT the one that was clicked.
var Thing0:Thing = new Thing();
var Thing1:Thing = new Thing();
var Thing2:Thing = new Thing();
// put Things into an Array
var Things:Array = [Thing0, Thing1, Thing2];
// add Event Listeners
for(var i:int = 0; i<Things.length; i++)
{
Things[i].addEventListener(MouseEvent.CLICK, handleClick);
}
function handleClick(e:MouseEvent):void
{
// which Thing was clicked?
var clickedThing:Thing = e.target;
for(var i:int = 0; i<Things.length; i++)
{
if(Things[i] != clickedThing)
{
// do something to this Thing
// ....
// ....
}
}
}
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.