00:00
00:00
Newgrounds Background Image Theme

EggSmash just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

functions reading which MC used?

291 Views | 2 Replies
New Topic Respond to this Topic

Is there a way to read which MC I apply my event listener to?

medalMC1.addEventListener(MouseEvent.MOUSE_OVER, MouseOver);
medalMC2.addEventListener(MouseEvent.MOUSE_OVER, MouseOver);
medalMC3.addEventListener(MouseEvent.MOUSE_OVER, MouseOver);

function MouseOver(event:MouseEvent):void {
	[insertAppliedMC].alpha = 0.5;
}

Maybe it's not possible?

**Updated**

Something like this would be cool

medalLvl1.addEventListener(MouseEvent.MOUSE_OVER, MouseOver, medalLvl1);
function MouseOver(event:MouseEvent, blah):void {
	trace(blah);
}

Response to functions reading which MC used? 2017-01-01 15:30:14


You can use the target property to access the object which triggered the event; just cast it as a MovieClip and do whatever you want with it:

function MouseOver(event:MouseEvent):void {
  var mc:MovieClip = event.target as MovieClip;
  mc.alpha = 0.5;
}

The target and currentTarget properties are used to access the objects that triggered events based on what is passed to your event listener (i.e. the function).

Response to functions reading which MC used? 2017-01-01 15:33:02


At 1/1/17 03:30 PM, Diki wrote: You can use the target property to access the object which triggered the event; just cast it as a MovieClip and do whatever you want with it:

Amazing, thanks Diki!!