The fastest easiest way to get it right.

subscribeToEvent

NAME

x6events.subscribeToEvent

FUNCTION

The Javascript method x6events.subscribeToEvent allows an object to subscribe to a named event. That object will then be notified whenever the event fires. See the method x6events.notify for more information on how the notification is handled.

INPUTS


  • eventName - Any string. There is no validation of the eventName, so misspellings will result in your object not being notified.
  • id - the Id of the object

NOTES



RESULT

No return value

SEE ALSO

x6events.fireEvent

SOURCE

subscribeToEvent: function(eventName,id) {
    if(id=='undefined') {
        x6.console.error('x6events.subscribeToEvent.  Second parameter '
            +' undefined.  First parameter: '+eventName
        );
    }
    else if(id==null) {
        x6.console.error('x6events.subscribeToEvent.  Second parameter '
            +' null.  First parameter: '+eventName
        );
    }
    else {        
        // First determine if we have any listeners for this
        // event at all.  If not, make up the empty object
        if( typeof(this.subscribers[eventName])=='undefined') {
            this.subscribers[eventName] = [ ];
        }
        if(this.subscribers[eventName].indexOf(id)==-1) {
            this.subscribers[eventName].push(id);
        }
        if( typeof(this.subsById[id])=='undefined') {
            this.subsById[id] = [ ];
        }
        if(this.subsById[id].indexOf(eventName)==-1) {
            this.subsById[id].push(eventName);
        }
    }
},

User Comments

There are no user comments yet on this page.


Add A Comment

Comments will not appear until after they are moderated. Comments are usually moderated within a few hours on weekdays, but may take longer on weekends and holidays.

Name or nickname: (This will appear with your comment)


Email (this will never be displayed)


Enter your comment here. Use [b] and [/b] for bold, [i] and [/i] for italic, and [pre] and [/pre] for code samples. All literal HTML and PHP that you enter will be escaped out and displayed as you enter it.


Home |  Documentation |  Download |  Credits |  Contact |  Login
Andromeda © Copyright 2004-2010, Licensed under the GPL Version 2