SFS.Connection problem in first example
Posted: 30 May 2011, 19:44
Hi! I'm just starting out in smartfoxserver and I've run into a problem while following the example in the youtube tutorial for creating a flash application. I tried searching but couldn't find anything, so apologies if this was answered already.
Problem: My code compiles correctly without any errors or warnings, but my onConnection function never triggers (is something wrong with my event listener?).
Main.mxml:
config.xml
Thanks in advance!
Problem: My code compiles correctly without any errors or warnings, but my onConnection function never triggers (is something wrong with my event listener?).
Main.mxml:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
initialize="init()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import com.smartfoxserver.v2.core.SFSBuddyEvent;
import com.smartfoxserver.v2.entities.Room;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.requests.JoinRoomRequest;
import com.smartfoxserver.v2.requests.LoginRequest;
import com.smartfoxserver.v2.requests.PublicMessageRequest;
import com.smartfoxserver.v2.SmartFox;
import com.smartfoxserver.v2.core.SFSEvent;
import flash.events.Event;
private var _sfs:SmartFox;
private function init():void
{
_sfs = new SmartFox(true);
_sfs.addEventListener(SFSEvent.CONNECTION, onConnection);
_sfs.addEventListener(SFSEvent.LOGIN, onLogin);
_sfs.addEventListener(SFSEvent.ROOM_JOIN, onRoomJoin);
_sfs.addEventListener(SFSEvent.PUBLIC_MESSAGE, onPublicMessage);
chatLog.text += 'Initializing...\n';
}
protected function login_clickHandler(event:MouseEvent):void
{
_sfs.loadConfig('config.xml');
chatLog.text += 'Loaded Config.\n';
}
private function onConnection(event:SFSEvent):void
{
if(event.params.success)
{
chatLog.text += 'Connection Success~~!!\n';
var request:LoginRequest = new LoginRequest('');
_sfs.send(request);
}
else
{
chatLog.text += 'Connection Failed...\n';
}
}
private function onLogin(event:SFSEvent):void
{
chatLog.text += 'Login Success!!\n';
var request:JoinRoomRequest = new JoinRoomRequest('Da Lobby');
_sfs.send(request);
}
private function onRoomJoin(event:SFSEvent):void
{
var room:Room = event.params.room;
chatLog.text += 'Joined Room: ' + room.name+ '\n';
}
private function onPublicMessage(event:SFSEvent):void
{
var user:User = event.params.sender;
chatLog.text += user.name + ": " + event.params.message + '\n';
}
protected function chat_clickHandler(event:MouseEvent):void
{
if (chatInput.text.length > 0)
{
var request:PublicMessageRequest = new PublicMessageRequest(chatInput.text);
_sfs.send(request);
chatInput.text = '';
}
}
protected function chatgarbage(event:MouseEvent):void
{
chatLog.text += 'lahbkshlkhs!!';
chatInput.text = '';
}
]]>
</fx:Script>
<s:Panel width="350" height="290" title="MyChat" horizontalCenter="0" verticalCenter="0">
<s:Button id="login" label="Login" x="10" y="10" click="login_clickHandler(event)"/>
<s:Button id="testchat" label="output and clear" x="150" y="10" click="chatgarbage(event)"/>
<s:TextArea id="chatLog" x="10" y="39" width="330" height="171"/>
<s:TextInput id="chatInput" x="10" y="220" width="250"/>
<s:Button id="chat" label="Chat!" x="268" y="221" click="chat_clickHandler(event)"/>
</s:Panel>
</s:Application>
Code: Select all
<SmartFoxConfig>
<!-- Mandatory Settings -->
<ip>127.0.0.1</ip>
<port>9933</port>
<zone>MyNUZone</zone>
<debug>true</debug>
<!---- For Generic http port comm. -->
<httpPort>8080</httpPort>
<udpIp>127.0.0.1</udpIp>
<udpPort>5152</udpPort>
</SmartFoxConfig>