Over 10 years of community discussion and knowledge are maintained here as a read-only archive.
is there a need for custom events when we can pass Array as notification body.
ackage org.edorado.edoboard.model.service{ import org.puremvc.as3.interfaces.INotifier; import org.puremvc.as3.patterns.observer.Notifier; import flash.net.NetConnection; import flash.events.NetStatusEvent; import org.edorado.edoboard.ApplicationFacade; /** * FMS connection Singleton * */ public class FMSConnectionService extends Notifier implements INotifier { private var nc:NetConnection; private static var instance:FMSConnectionService; public function FMSConnectionService() { setupConnection(); } /** * Create the required connection object and do any configuration */ private function setupConnection():void { //A NetConnection is the pipe between Flex/Air and Flash Media Server nc = new NetConnection(); //The NetStatusEvent is a dispatched status event for //NetConnection, NetStream, or SharedObject. //We want to know if the NetConnection has properly connected nc.addEventListener( NetStatusEvent.NET_STATUS, handlerOnNetStatus ); } // Singleton Service public static function getInstance() : FMSConnectionService { if ( instance == null ) instance = new FMSConnectionService( ); return instance as FMSConnectionService; } /** * Connect to the given URL */ public function connect(url:String):void { nc.connect(url); } /** * Disconnect the net connection */ public function close():void { nc.close(); } public function getNetConnection():NetConnection { return nc; } /** * This is the handler function of the NetStatusEvent for the NetConnection. * Here is where we can find out the connection status and send notifications * based on each result. */ private function handlerOnNetStatus( event:NetStatusEvent ):void { var info:Object = event.info; trace(info.code); //Checking the event.info.code for the current NetConnection status string switch(info.code) { //code == NetConnection.Connect.Success when Netconnection has successfully //connected case "NetConnection.Connect.Success": sendNotification(ApplicationFacade.CONNECT_SUCCESS, info.code); break; //code == NetConnection.Connect.Rejected when Netconnection did //not have permission to access the application. case "NetConnection.Connect.Rejected": sendNotification(ApplicationFacade.CONNECT_REJECTED, info.code); break; //code == NetConnection.Connect.Failed when Netconnection has failed to connect //either because your network connection is down or the server address doesn't exist. case "NetConnection.Connect.Failed": sendNotification(ApplicationFacade.CONNECT_FAILED, info.code); break; //code == NetConnection.Connect.Closed when Netconnection has been closed successfully. case "NetConnection.Connect.Closed": sendNotification(ApplicationFacade.CONNECT_CLOSED, info.code); break; } } }}