Sha256: a5ccdf7a4968da426b74e860cab8c6d8b019c8a8ae64e383f83a2eb98f06bbda

Contents?: true

Size: 1.66 KB

Versions: 28

Compression:

Stored size: 1.66 KB

Contents

import com.asunit.util.*;

class com.asunit.util.LocalMessageBroker extends Object implements Observable {
	private static var instance:LocalMessageBroker;
	private var msgs:Array;
	private var eventSrc:EventSource;
	
	private function LocalMessageBroker() {
		init();
	}
	
	private function init():Void {
		msgs = new Array();
		eventSrc = new EventSource();
	}
	
	public static function getInstance():LocalMessageBroker {
		if(instance == undefined) {
			instance = new LocalMessageBroker();
		}
		return instance;
	}
	
	public function send(msg:String, category:String):String {
		msgs.push({message:msg, category:category});
		eventSrc.broadcastMessage("onMessageSent", {event:"onMessageSent", message:msg, category:category});
		return msg;
	}
	
	public function toString():String {
		var str:String = "";
		for(var i:Number = 0; i < msgs.length; i++) {
			str += msgs[i] + "\n";
		}
		return str;
	}
	
	// Can accept either an event:String or an event:String[]
	// if the observer wants to subscribe to multiple events.
	public function addEventListener(event:String, observer:Object, scope:Object):Void {
		eventSrc.addEventListener(event, observer, scope);
	}
	
	public function addListener(observer:Object, scope:Object):Void {
		eventSrc.addListener(observer, scope);
	}

	// Should return bool false if handler ref was not found.
	// Should return bool true if handler ref was found
	public function removeEventListener(event:String, observer:Object):Boolean {
		return eventSrc.removeEventListener(event, observer);
	}
	
	public function removeListener(observer:Object):Boolean {
		return eventSrc.removeListener(observer);
	}
}

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
asproject-0.1.21 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as
asproject-0.1.27 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as
asproject-0.1.28 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as
asproject-0.1.29 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as
asproject-0.1.30 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as
asproject-0.1.31 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as
asproject-0.1.33 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as
asproject-0.1.32 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as
asproject-0.1.37 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as
asproject-0.1.36 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as
asproject-0.1.35 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as
asproject-0.1.34 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as
asproject-0.1.42 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as
asproject-0.1.44 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as
asproject-0.1.40 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as
asproject-0.1.38 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as
asproject-0.1.41 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as
asproject-0.1.43 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as
asproject-0.1.68 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as
asproject-0.1.60 templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as