Connecting the dots…

Thoughts on Web and Personal Development

yui - custom event

without comments

Note to self on how to setup custom even.
Step 1: Define a custom event

1
var onCustomEvent1 = new YAHOO.util.CustomEvent('onCustomEvent');

Step 2: Make methods subscribe to the event

1
2
onCustomEvent1.subscribe(method1);
onCustomEvent1.subscribe(method2);

etc.You can also pass arguments to the subscribe method, which can be accessed by the subscribed method, as explained below.

Step 3: Whenever that event is supposed to be triggerd, cause the event to be executed

onCustomEvent1.fire();

You can also pass arguments to the fire method, these arguments can then be accessed in the subscribe method explained below.

1
2
onCustomEvent1.fire({action:'fire'});
function method1(event, arguments, obj) {}
  • event returns the name of the custom event
  • arguments is the set of arguments that are passed in the fire event
  • obj is the argument that is passed in the subscribe method.

Calling the fire() method causes all the listener methods to get fired. Simple stuff, amazing uses as well, maybe its just me but i am sure i wont remember this the second time i have look at it.

Share:
  • Digg
  • del.icio.us
  • Google
  • Sphinn
  • Facebook
  • Mixx
  • LinkedIn
  • Ma.gnolia
  • StumbleUpon
  • TwitThis
  • Yahoo! Buzz

Written by rp

February 22nd, 2008 at 3:46 am

Leave a Reply