Author Topic: How do you correctly remove an event receiver?  (Read 3184 times)

Disastercake

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 87
  • www.disastercake.com
    • View Profile
    • Disastercake
How do you correctly remove an event receiver?
« on: September 12, 2012, 12:12:38 AM »
I am using the code:

  1. MyTweenColor.eventReceiver = null;
  2.         MyTweenColor.callWhenFinished = "";

To make it so that if this tween happens again, it does not send out a message again.  However, this is not working properly and it still calls the same object and function even though it shows in the inspector that they are not set.  What is the proper way to remove these receivers?  Also, what is the proper way to replace them with a new one via script?
Creator of Soul Saga.
http://www.disastercake.com

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How do you correctly remove an event receiver?
« Reply #1 on: September 12, 2012, 12:25:58 AM »
Code straight from UITweener:
  1.                         // Notify the event listener target
  2.                         if (eventReceiver != null && !string.IsNullOrEmpty(callWhenFinished))
  3.                         {
  4.                                 eventReceiver.SendMessage(callWhenFinished, this, SendMessageOptions.DontRequireReceiver);
  5.                         }
So if either is null, nothing will happen. Are you sure it's coming from this place and not the event delegate you set elsewhere?

Disastercake

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 87
  • www.disastercake.com
    • View Profile
    • Disastercake
Re: How do you correctly remove an event receiver?
« Reply #2 on: September 12, 2012, 12:49:56 AM »
I double checked and it looks like I had both objects that were fading in call the same function when they were done.  So I was only disabling one.  I've fixed it by only having one of the objects make the call.  Thanks for helping me ArenMook!
Creator of Soul Saga.
http://www.disastercake.com