Everything work fine up untill I tried to use SFSRoomVariable
I tried used the example included here: http://docs2x.smartfoxserver.com/api-do ... quest.html
I get error 1180: Call to a possibly undefined method SFSRoomVariable.
1172: Definition com.smartfoxserver.v2.entities:variables could not be found.
code:
The SFSvariable code is at the end of the code
Code: Select all
package {
import com.smartfoxserver.v2.SmartFox;
import com.smartfoxserver.v2.core.SFSEvent;
import com.smartfoxserver.v2.entities.*;
import com.smartfoxserver.v2.entities.data.*;
import com.smartfoxserver.v2.requests.*;
import com.smartfoxserver.v2.entities.variables;
import flash.display.*;
import flash.events.*;
import flash.system.Security;
public class makecity {
private var sfs:SmartFox;
public static var username:String;
public static var cityname:String;
public static var bt_string:Boolean;
public static var ta_debug2:String=" ";
public static var key_debug:Boolean=false;
public var msg:String;
//constructor function
public function makecity(username:String,cityname:String,bt_string:Boolean,ta_debug2:String,key_debug:Boolean):void {
makecity.username=username;
makecity.cityname=cityname;
makecity.bt_string=bt_string;
sfs = new SmartFox();
sfs.debug=false;//debug feature on
///////////////////////////////////////////////////
// Add SFS2X handshake connection event listeners//
///////////////////////////////////////////////////
sfs.addEventListener(SFSEvent.CONNECTION, onConnection);
sfs.addEventListener(SFSEvent.CONNECTION_LOST, onConnectionLost);
sfs.addEventListener(SFSEvent.CONFIG_LOAD_SUCCESS, onConfigLoadSuccess);
sfs.addEventListener(SFSEvent.CONFIG_LOAD_FAILURE, onConfigLoadFailure);
///////////////////////////////////
//Add SFS2X login event listeners//
///////////////////////////////////
sfs.addEventListener(SFSEvent.LOGIN, onLogin);
sfs.addEventListener(SFSEvent.LOGIN_ERROR, onLoginError);
///////////////////////////////////
// Add SFS2X room event listeners//
///////////////////////////////////
sfs.addEventListener(SFSEvent.ROOM_ADD, onRoomAdded);
sfs.addEventListener(SFSEvent.ROOM_CREATION_ERROR, onRoomCreationError);
//virtual button is true then..
if (bt_string==true) {
sfs.loadConfig();
makecity.key_debug=false;
}
//dtrace//
}
/////////////////////////////////
//handshake connection function//
/////////////////////////////////
private function onConnection(evt:SFSEvent):void {
if (evt.params.success) {
handshakedTrace("\n Connection Success!");
sfs.send( new LoginRequest(makecity.username,"", "GameLobby") );//login to zone after handshake sucess !
//after sfs.send go to logon functions
} else {
handshakedTrace("\n Connection Failure: " + evt.params.errorMessage);
}
}
private function onConnectionLost(evt:SFSEvent):void {
handshakedTrace("\n Connection was lost. Reason: " + evt.params.reason);
makecity.key_debug=true;
}
private function onConfigLoadSuccess(evt:SFSEvent):void {
handshakedTrace("\n Config load success!"+"\n Server settings: " + sfs.config.host + ":" + sfs.config.port);
}
private function onConfigLoadFailure(evt:SFSEvent):void {
handshakedTrace("\n Config load failure!!!");
makecity.key_debug=true;
}
///////////////////
//logon functions//
///////////////////
private function onLogin(evt:SFSEvent):void {
logondTrace("\n Login success: " + evt.params.user.name);
var settings:RoomSettings=new RoomSettings(makecity.cityname);
settings.maxUsers=40;
settings.groupId="default";
sfs.send(new CreateRoomRequest(settings,true,null));//create a room after zone login !
//after sfs.send here go to create room function
}
private function onLoginError(evt:SFSEvent):void {
logondTrace("\n Login failed: " + evt.params.errorMessage);
makecity.key_debug=true;
}
/////////////////////////
//room create functions//
/////////////////////////
private function onRoomAdded(evt:SFSEvent):void {
createdTrace("\n A new Room was added: " + evt.params.room );
dummyvariable();//add variables
//sfs.send( new JoinRoomRequest(makecity.cityname) );//join the room that just been created by the user.
//next step is room enter function
}
private function onRoomCreationError(evt:SFSEvent):void {
createdTrace("\n An error occurred while attempting to create the Room: " + evt.params.errorMessage);
makecity.key_debug=true;
}
////////////////
//Debug output//
////////////////
private function handshakedTrace(msg:String):void {
makecity.ta_debug2+=msg;
}
private function logondTrace(msg:String):void {
makecity.ta_debug2+=msg;
}
private function createdTrace(msg:String):void {
makecity.ta_debug2+=msg;
makecity.key_debug=true;
}
//dummy variables//
//where I get error//
public function dummyvariable():void {
sfs.addEventListener(SFSEvent.ROOM_VARIABLES_UPDATE, onRoomVarsUpdate);
// Create some Room Variables
var roomVars:Array=[];
roomVars.push(new SFSRoomVariable("gameStarted", false));
//roomVars.push(new SFSRoomVariable("gameType", "normal"));
//roomVars.push(new SFSRoomVariable("minRank", 10));
sfs.send(new SetRoomVariablesRequest(roomVars));
}
public function onRoomVarsUpdate(evt:SFSEvent):void {
var changedVars:Array=evt.params.changedVars as Array;
var room:Room=evt.params.room as Room;
// Check if the "gameStarted" variable was changed
if (changedVars.indexOf("gameStarted")!=-1) {
if (room.getVariable("gameStarted").getBoolValue()==true) {
trace("Game started");
} else {
trace("Game stopped");
}
}
}
//end of dummy section//
}
}