Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

isBroadcaster.as

Name: isBroadcaster() - determines if object has been initiated by ASBroadcaster and has listeners
Author: senocular: www.senocular.com
Date: 1899-12-31T00:29:04.700
Documentation:
Object ISBROADCASTER (for ASBroadcaster uses): Checks an
Object for the _listeners property and sees if it has at least one
element within, if so, true is returned.
 
Returns:
- true if the object is considered a broadcaster (has atleast 1 listener) and
false if not.

Example:
General = {};
Troop = {};
trace(General.isBroadcaster()); // false
ASBroadcaster.initialize(General);
trace(General.isBroadcaster()); // false
General.addListener(Troop);
trace(General.isBroadcaster()); // true

1
2
3
4
5
6
// since broadcasting objects arent instances of the broadcaster
// object and are just general objects themselves, Object.prototype
// is used for initiated ASB objects
Object.prototype.isBroadcaster = function(){
	return (this._listeners.length) ? true : false;
}