/** * Copyright © 2002 Macromedia, Inc. All rights reserved. * * FCSimpleConnect * Moving or modifying this file may affect the applications installed on this server. */ #initclip 1 // function FCSimpleConnectClass() { this.init(); } // FCSimpleConnectClass.prototype = new MovieClip(); // Object.registerClass("FCSimpleConnectSymbol", FCSimpleConnectClass); // FCSimpleConnectClass.prototype.onUnload = function() { this.close(); }; // Initializes this Component, hides the Change Name Pop-up dialog // Creates a Key Listener for Keys pressed inside the User Name text box FCSimpleConnectClass.prototype.init = function() { // this.name = (this._name == null ? "_DEFAULT_" : this._name); this.prefix = "FCSimpleConnect." + this.name + "."; // // Login text loses focus this.username_txt.onKillFocus = function() { this._parent.hasFocus = false; }; // Login text gets focus this.username_txt.onSetFocus = function() { this._parent.hasFocus = true; }; // Listens for a key down and checks to see if Enter was pressed from the login text box // Cancels the Login/Change if the user hits Escape this.enterListener = new Object(); this.enterListener.owner = this; this.enterListener.onKeyDown = function() { if (this.owner.hasFocus && Key.isDown(Key.ENTER)) { this.owner.loginChange(); } else { this.owner.intervalID = setInterval(this.owner, "checkName", 10); } }; Key.addListener(this.enterListener); var tempList = (new Array).concat(this.fcComponents); this.fcComponents = []; for(var i in tempList) { this.fcComponents[tempList[i]] = tempList[i]; } }; FCSimpleConnectClass.prototype.addComponent = function(component) { this.fcComponents[component] = component; } FCSimpleConnectClass.prototype.removeComponent = function(component) { delete this.fcComponents[component]; } // FCSimpleConnectClass.prototype.connect = function(nc) { this.nc = nc; if (this.nc.FCSimpleConnect == null) { this.nc.FCSimpleConnect = {}; } this.nc.FCSimpleConnect[this.name] = this; // // Need to call connect on our server side counterpart first this.nc.call(this.prefix + "connect", null, this.username); // }; // FCSimpleConnectClass.prototype.close = function() { // Let our server side counterpart know that we are going away this.nc.call(this.prefix + "close", null); // this.nc.FCSimpleConnect[this.name] = null; this.nc = null; }; // Establishes a NetConnection using the appDirectory parameter, // User Name and appInstance if available // Handles basic NetConnection onStatus events // and Attaches other components specified in the FlashCom Components // parameter to the new NetConnection FCSimpleConnectClass.prototype.serverConnect = function(username, appInstance) { // Cleanup components this.close(); for(var i in this.fcComponents) { this._parent[this.fcComponents[i]].close(); } this.main_nc.close(); // Create a new net connection to the server this.main_nc = new NetConnection(); this.main_nc.owner = this; // Uses an app instance if it's passed as a parameter to the movie if (appInstance != null) { this.appDirectory += "/" + appInstance; } // Check for last User Name, user username passed if supplied if (username != null) { this.username = username; this.changeName_btn._visible = false; this.inputBg_mc._visible = false; } else { this.local_so = SharedObject.getLocal("FCUsername", "/"); if (this.local_so.data.username != null) { this.username = this.local_so.data.username; this.changeName_btn.setEnabled(true); } } // this.main_nc.connect(this.appDirectory, this.username, password); // Attach components this.setUsername(this.username); this.connect(this.main_nc); for(var i in this.fcComponents) { this._parent[this.fcComponents[i]].setUsername(this.username); this._parent[this.fcComponents[i]].connect(this.main_nc); } }; // Update the username for this component FCSimpleConnectClass.prototype.setUsername = function(newName) { if (newName == null) { this.username_txt.text = "Your Name"; } else { this.username = newName; this.username_txt.text = newName; } }; // Callback from server when name is changed FCSimpleConnectClass.prototype.changedName = function(newName) { //trace("changeName" + newName); for(var i in this.fcComponents) { this._parent[this.fcComponents[i]].setUsername(newName); } }; // Sends a changeName call to the server to actually change this user's name FCSimpleConnectClass.prototype.loginChange = function() { // Only if the username has actually changed send it the server if (this.username_txt.text.length == 0) { this.changeName_btn.setEnabled(false); } else if (this.username != this.username_txt.text) { this.username = this.username_txt.text; this.main_nc.call(this.prefix + "changeName", null, this.username); this.local_so.data.username = this.username; this.local_so.flush(); } }; // FCSimpleConnectClass.prototype.checkName = function() { clearInterval(this.intervalID); var newName = this.username_txt.text; var btn = this.changeName_btn; if (newName.length == 0) { btn.setEnabled(false); } else if (newName.charAt(0) == " ") { btn.setEnabled(false); } else if (btn.enabled == false) { btn.setEnabled(true); } }; // FCSimpleConnectClass.prototype.setSize = function(newWidth, newHeight) { // this._xscale = 100; this._yscale = 100; // this.username_txt._width = newWidth - 73; this.changeName_btn._x = newWidth - this.changeName_btn._width; this.inputBg_mc._width = this.username_txt._width; }; // #endinitclip // B-) // This is called from outside of initclip to make sure all // the other components have been inited, this establishes // a new NetConnection and connects any other FlashCom Components this.setSize(this._width, this._height); this.serverConnect(_parent.username, _parent.appInstance); this.main_nc.call(this.prefix + "changeName", null, this.username); //