//----------------------------------------------------------------------------- // 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. // Root variables currentChoice = null; // Current short name for the application/instance // the user wants to connect to. nc = null; // NetConnection reference. traceBuffer_so = null; // Remote shared object belonging to the // application/instance we are connected to. roomList_so = null; // Remote shared object belonging to the // lobby00/lobby instance but also proxied by // the rooms00/room_x instances // Left align the text in the four push buttons. pbLobby.setStyleProperty("textAlign", 'left'); pbRoom_1.setStyleProperty("textAlign", 'left'); pbRoom_2.setStyleProperty("textAlign", 'left'); pbRoom_3.setStyleProperty("textAlign", 'left'); /** * Simple replacement for the trace function. * Writes into the tClientTrace text field * and scrolls it to the bottom. **/ function writeln(str){ tClientTrace.text += str + "\n"; tClientTrace.scroll = tClientTrace.maxscroll; } /** * showStatus loops through the indicator movie clips * and uses them to show the current network status. * This could be done more elegantly using OOP and * avoiding eval. **/ function showStatus(appInstance, status){ // Closed, Waiting, Open. appInstance = 'i' + appInstance; iNames = ["iLobby", "iein", "izwei", "idrei"]; for (var i in iNames){ if (appInstance == iNames[i]){ eval(iNames[i]).gotoAndStop(status); } else{ eval(iNames[i]).gotoAndStop("Closed"); } } } /** * When a change occurs in the traceBuffer_so get the full text from the * buffer property and display it in the remote application (tInstanceTrace) * window. **/ function traceSO_onSync(list){ tInstanceTrace.text = this.data.buffer; tInstanceTrace.scroll = tInstanceTrace.maxscroll; } /** * When a change occurs in the roomList_so get the integer stored in * each property and display it in the client trace window. * Warning: this is a very very simple scheme. Normally you wouldn't just * store a single integer in each property of a room list. You would be * more likely to store an object with more information than just the number * of visitors. **/ function roomSO_onSync(list){ var totalClients = 0; for (var p in this.data){ writeln("There are " + this.data[p] + " visitor(s) in " + p + "."); totalClients += this.data[p]; } writeln("There are a total of " + totalClients + " client(s) connected to the system."); } /** * Whenever a new network connection is established this is called to * setup the remote objects. **/ function initSharedObjects(){ traceBuffer_so = SharedObject.getRemote('traceBuffer', nc.uri); traceBuffer_so.onSync = traceSO_onSync; traceBuffer_so.connect(nc); roomList_so = SharedObject.getRemote('roomList', nc.uri); roomList_so.onSync = roomSO_onSync; roomList_so.connect(nc); } /** * onStatus handler for the one NetConnection object used here. * Reports each info.code and then adjusts the indicators to * reflect the connection status. If the connection has just * been established initSharedObjects is called. **/ function NetConnection_onStatus(info){ writeln ("NetConnection.onStatus> info.code: " + info.code); if (nc.uri.length > 0){ writeln ("NetConnection.onStatus> nc.uri: " + nc.uri); } if (this.isConnected){ showStatus(currentChoice, "Open"); } else{ showStatus(currentChoice, "Closed"); } if (info.code == "NetConnection.Connect.Success"){ initSharedObjects(); } } // Create a map of the last part of the button labels // to the relative rtmp addresses. addressHash = { Lobby: "rtmp:/lobby_rooms/lobby", ein: "rtmp:/lobby_rooms/room_1", zwei: "rtmp:/lobby_rooms/room_2", drei: "rtmp:/lobby_rooms/room_3" }; /** * Handle push button connection requests. **/ function doConnect(btn){ // Get the last part of the button label. currentChoice = btn.label.split(' ').pop(); // If there is another connection drop it. if (nc){ nc.close(); } // Otherwise create a network connection and // and setup the onStatus handler. else{ nc = new NetConnection(); nc.onStatus = NetConnection_onStatus; } var result = nc.connect(addressHash[currentChoice]); if (result){ showStatus(currentChoice, "Waiting"); } }