Why does "-= AnimationEndedEventHandler" work in the tutorial code but not in code for my own class?

Sep 16, 2008 at 9:56 AM
Can anyone tell me why it's possible to use "-=" to nullify a .AnimationEnded event handler in the example code but the same code seems to have no effect inside my custom class?  I am adding AnimationController as fields to a custom GameEnemy class and trying to "-=" a .AnimationEnded event handler inside the said class but to no avail.  I can see in the debugger the .AnimationEnded event handler go null and back inside the tutorial code but my own class doesn't do the same thing.  What am I doing wrong?!?
Sep 17, 2008 at 12:36 AM
Edited Sep 17, 2008 at 12:42 AM
I found out what's going on.  I was adding my custom event handler through a method by passing in the animation controller as an argument like so:$0$0$0$0play_Anim(Anim, Anim_AnimationEnded);$0$0$0$0$0Iinside play_Anim, the event handler was assigned so:$0$0$0$0$0void play_eAnim(AnimationController animToPlay, EventHandler animToPlayEnded)$0$0{$0$0   animToPlay.ElapsedTime = 0;$0$0   animToPlay.AnimationEnded += new EventHandler(animToPlayEnded); <-- This was the culprit.$0$0   RunController(animToPlay);$0$0}$0$0$0$0$0Instead, if I just assign the event handler directly like so:$0$0$0$0$0Anim.AnimationEnded += new EventHandler(Anim_AnimationEnded);$0$0$0$0$0then the following code is able to nullify the event handler.$0$0$0$0$0Anim.AnimationEnded -= Anim_AnimationEnded;$0$0$0$0$0Don't know why this is so but I'm just glad that my code now work as expected. :)$0