petermaxo -> RE: Flash Q&A thread 3 (5/18/2007 21:27:41)
|
by the way, I checked the code in Flash and you missed a } (bold and inserted.). Also, you switch programming languages rather abruptly in the bold area. quote:
ORIGINAL: SirSchmoopy whts wrong with this code???? import it.gotoandplay.smartfoxserver.* stop() ip = "127.0.0.1" port = 9339 smartfox = new SmartFoxClient() smartfox.onConnection = handleConnection smartfox.connect(ip, port) //---------------------------------------------------------- // Handle connection response from server //---------------------------------------------------------- function handleConnection(success) { if (success) { status_txt.text = "Connection succesfull!" } else { status_txt.text = "Can't connect!" } } smartfox.onRoomListUpdate = function(roomList) { roomList_lb.removeAll() for (var i in roomList) { var room = roomList roomList_lb.addItem(room.getName() + " (" + room.getUserCount() + ")", room.getId()) } roomList_lb.sortItemsBy("label", "ASC") // Join the default room this.autoJoin() } smartfox.onUserCountChange = function(roomObj) { updateRoomStatus(roomObj.getId()) } function updateRoomStatus(roomId) { var room = smartfox.roomList[roomId] var newLabel = room.name + " (" + room.getUserCount() + ")" for (i=0; i < roomList_lb.getLength(); i++) { var item = roomList_lb.getItemAt(i) if (roomId == item.data) { roomList_lb.replaceItemAt(i, newLabel, item.data) break; } } } //---------------------------------------------------------- // Setup components callback functions //---------------------------------------------------------- roomList_lb.setChangeHandler("changeRoom") userList_lb.setChangeHandler("userSelected") function changeRoom() { var item = roomList_lb.getSelectedItem() // new Room id var newRoom = item.data if (newRoom != smartfox.activeRoomId) { // Check if new room is password protected var priv = smartfox.getRoom(newRoom).isPrivate() if (priv) { // Save newroom as _global for later use _global.newRoom = newRoom showWindow("passwordWindow") } else { // Pass the room id smartfox.joinRoom(item.data) } } var priv = smartfox.getRoom(newRoom).isPrivate() smartfox.joinRoom(item.data) function loginProtectedRoom(pwd) { hideWindow("passwordWindow") smartfox.joinRoom(_global.newRoom, pwd) } joinRoom = function(newRoom, pword, dontLeave, oldRoom) smartfox.onJoinRoomError = function(errorMsg) { var win = showWindow("errorWindow") win.errorMsg.text = errorMsg // Put the selected room in the combo box back to its old value resetRoomSelected(smartfox.activeRoomId) } <Zone name="simpleChat"> <Rooms> <Room name="The Cottage" maxUsers="70" isPrivate="false" isTemp="false" isGame="false" autoJoin="true" /> <Room name="The Tree" maxUsers="70" isPrivate="false" isTemp="false" isGame="false"/> <Room name="The Pool" maxUsers="70" isPrivate="false" isTemp="false" isGame="false" /> <Room name="The Bathroom(lol)" maxUsers="70" isPrivate="false" isTemp="false" isGame="false" /> <Room name="The Tradin' Place Foo!" maxUsers="70" isPrivate="false" isTemp="false" isGame="false" /> <Room name="The Big Fieldy Place Room" maxUsers="50" isPrivate="true" isTemp="false" pwd="piddu" isGame="false" /> </Rooms> </Zone> createRoom(roomObj) function makeNewRoom() { showWindow("newRoomWindow") } } function createRoom(name, pwd, max) { hideWindow("newRoomWindow") var roomObj = new Object() roomObj.name = name roomObj.password = pwd roomObj.maxUsers = max smartfox.createRoom(roomObj) } smartfox.onCreateRoomError = function(errorMsg) { var win = showWindow("errorWindow") win.errorMsg.text = errorMsg } function userSelected() { uid = userList_lb.getSelectedItem().data // If it's not me... if (uid != smartfox.myUserId) { // store the recipient for later use _global.pmUid = uid var win = showWindow("pmWindow") var uList = smartfox.getActiveRoom().getUserList() var targetUsr = uList[uid] win.title_txt.text = "Send a private message to " + targetUsr.getName() } } function sendMessage() { var m = message.text if (m.length > 0) { _parent.sendPrivateMessage(m, _global.pmUid) message.text = "" } } smartfox.onConnectionLost = function() { gotoAndStop("connect") } Edit: stoopid syntax error!!! This code has no syntax errors, but it may not do what you want it to. import it.gotoandplay.smartfoxserver.* stop() ip = "127.0.0.1" port = 9339 smartfox = new SmartFoxClient() smartfox.onConnection = handleConnection smartfox.connect(ip, port) //---------------------------------------------------------- // Handle connection response from server //---------------------------------------------------------- function handleConnection(success) { if (success) { status_txt.text = "Connection succesfull!" }else{ status_txt.text = "Can't connect!" } } smartfox.onRoomListUpdate = function(roomList) { roomList_lb.removeAll() for (var i in roomList) { var room = roomList roomList_lb.addItem(room.getName() + " (" + room.getUserCount() + ")", room.getId()) }roomList_lb.sortItemsBy("label", "ASC") // Join the default room this.autoJoin() } smartfox.onUserCountChange = function(roomObj) { updateRoomStatus(roomObj.getId()) } function updateRoomStatus(roomId) { var room = smartfox.roomList[roomId] var newLabel = room.name + " (" + room.getUserCount() + ")" for (i=0; i < roomList_lb.getLength(); i++){ var item = roomList_lb.getItemAt(i) if (roomId == item.data){ roomList_lb.replaceItemAt(i, newLabel, item.data) break; } } } //---------------------------------------------------------- // Setup components callback functions //---------------------------------------------------------- roomList_lb.setChangeHandler("changeRoom") userList_lb.setChangeHandler("userSelected") function changeRoom() { var item = roomList_lb.getSelectedItem() // new Room id var newRoom = item.data if (newRoom != smartfox.activeRoomId) { // Check if new room is password protected var priv = smartfox.getRoom(newRoom).isPrivate() if (priv) { // Save newroom as _global for later use _global.newRoom = newRoom showWindow("passwordWindow") }else{ // Pass the room id smartfox.joinRoom(item.data) } }var priv = smartfox.getRoom(newRoom).isPrivate() smartfox.joinRoom(item.data) } function loginProtectedRoom(pwd) { hideWindow("passwordWindow") smartfox.joinRoom(_global.newRoom, pwd) } joinRoom = function(newRoom, pword, dontLeave, oldRoom){ smartfox.onJoinRoomError = function(errorMsg){ var win = showWindow("errorWindow") win.errorMsg.text = errorMsg // Put the selected room in the combo box back to its old value resetRoomSelected(smartfox.activeRoomId) } } createRoom(roomObj) function makeNewRoom() { showWindow("newRoomWindow") }function createRoom(name, pwd, max) { hideWindow("newRoomWindow") var roomObj = new Object() roomObj.name = name roomObj.password = pwd roomObj.maxUsers = max smartfox.createRoom(roomObj) } smartfox.onCreateRoomError = function(errorMsg){ var win = showWindow("errorWindow") win.errorMsg.text = errorMsg } function userSelected(){ uid = userList_lb.getSelectedItem().data // If it's not me... if (uid != smartfox.myUserId) { // store the recipient for later use _global.pmUid = uid var win = showWindow("pmWindow") var uList = smartfox.getActiveRoom().getUserList() var targetUsr = uList[uid] win.title_txt.text = "Send a private message to " + targetUsr.getName() } } function sendMessage() { var m = message.text if (m.length > 0) { _parent.sendPrivateMessage(m, _global.pmUid) message.text = "" } } smartfox.onConnectionLost = function() { gotoAndStop("connect") }
|
|
|
|