//----------------------------------------------------------------------------- // Copyright (c) 2002 Ryerson University. All Rights Reserved. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. //----------------------------------------------------------------------------- // This software was written in order to experiment with the Macromedia // Flash Communication Server MX and is not intended to demonstrate the best // way to write code for Flash or FlashCom. //----------------------------------------------------------------------------- // // NetConnector.as Version 1.00 // Written by Brian Lesser // September/2002 // Requires the existance of a global hash code manager object named: // "hashCodeManager" and the broadcast converter class. //----------------------------------------------------------------------------- /** * NetConnector is a simple subclass of NetConnection with a * predefined onStatus handler and is listenable to notify * listeners when the connection status changes. Listeners * must implement an onConnect(nc, info) method. * This class relies on the existance of the * hashCodeManager object and the Listenable class. * Unlike the NetConnection object this class expects a URI * to be passed to the constructor function. In some cases * objects such as the RemoteObjectManager may have to be * notified of a connection before other objects. * The notify method sorts by hash code before notifing listeners. * Since the hashCodeManager provides numeric strings the earlier * an object get a hash code the more likely it will be a lower * number. */ function NetConnector(address){ super(); // Make this instance listenable BroadcastConverter.makeOrderedBroadcaster(this); // Keep the URI for later. this.address = address; } /* Subclass NeConnection */ NetConnector.prototype = new NetConnection(); NetConnector.prototype.setAddress = function(address){ this.address = address; } NetConnector.prototype.connect = function(userName, password){ // Keep credentials incase we need to try again. // Assuming only a user name and password need to be passed // is simplistic. this.userName = userName; this.password = password; var result = super.connect(this.address, userName, password); if (result){ this.notify( {code: "NetConnection.Connect.Waiting"}, 'onStatus' ); } else{ this.notify([{code: "NetConnection.Connect.Failed"}], 'onStatus' ); } return result; } NetConnector.prototype.reConnect = function(){ this.connect(this.userName, this.password); }