Skip to Content »

FlashApe » Different Delegate

 Different Delegate

  • December 16th, 2006
  • 7:12 pm

By now, most people know what the Delegate class is about. A lot of people also know it’s limitations, such as not being able to pass extra parameters to the method being delegated too. Joey Lott’s Proxy class too care of that issue. While adding stuff to actionscriptclasses.com, I came across this “refined” Delegate class by Steve Webster, which not only allows for the passing of additional parameters, but also adds a reference to the anonymous function that is created, allowing for easy removal of the event listener.

4 People had this to say...

Gravatar

I understand the use-case for wanting to remove an anonymous listener, but I don’t understand the parameters need. Can you explain what it is you are doing with these parameters, and how you pass them in?

I’ve lived so long using the regular 7.2 Delegate, I never imagined living without it, so having a hard time wrapping my head around “passing” parameters.

Gravatar
  • rich
  • December 16th, 2006
  • 11:32 pm

me personally, I have yet to come across a situation where I actually need to pass extra params to the delegate function. I guess most of the time most of my delegate functions are set up as event listeners, so i either access the properties i need either through eventObject.target or whatever class object I am delegating to’s own properties.

I more interested in getting the reference to the anonymous function, since I used to store those as properties, which seemed kinda kludgy to me.

Gravatar

One problem I’ve had with the refined Delegate class is where you sometimes pass arguments to a function and sometimes don’t (e.g. the function is registered as an event listener and sometimes also triggered directly by code). It might just have been sloppy coding on my part but a few times I ran into bugs because the reference to the anonymous function gets tagged onto the end of however many arguments are created. So you can’t lazily pass no arguments assuming that this will mean undefined is passed to the function…
Like I said, probably due to lazy coding on my part but caused confusion and means you can’t simply switch over from the MM Delegate….

Gravatar
  • rich
  • December 17th, 2006
  • 11:20 am

yeah, i see your point. you’d need to pop() the last argument in the array then check for undefined. I would say that’s expected functionality from that Delegate class though, not a bug.

Want your say?

* Required fields. Your e-mail address will not be published on this site


You can use the following XHTML tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>