我搜索了 Google、FMS Guru 和大量 Adobe 开发人员教程。我有点困惑如何从客户端将变量作为参数发送到共享对象或客户端对象中,以便我可以从 main.asc 文件中获取和处理服务器端的变量。
例如,如何使用创建的 SWF 中的 AS3 将用户名、用户 ID、性别、用户类型和生日变量发送到 main.asc 文件?
来自chat.mxml
private var xmlstring:String = "http://www.blah.com/xml.xml";
private var userType:String;
private var userCountText:String;
protected function getXML():void {
XML.ignoreWhitespace = true;
var myLoader:URLLoader=new URLLoader();
myLoader.load(new URLRequest(ownerstring));
myLoader.addEventListener(Event.COMPLETE, processXML);
}
protected function processXML(e:Event):void {
var myXML:XML = XML(e.target.data)
for (var i:int = 0; i<myXML.*.length(); i++){
xinstance = myXML.owner[0];
xuserid = myXML.owner[1];
xusername = myXML.owner[2];
xphoto = myXML.owner[3];
xroomowner = myXML.owner[4];
}
//xinstance = myXML.broadcastowner.owner.(@title == "instance");
//xuserid = myXML.broadcastowner.owner.(@title == "userid");
//xusername = myXML.broadcastowner.owner.(@title == "username");
//xphoto = myXML.broadcastowner.owner.(@title == "photo");
//xroomowner = myXML.broadcastowner.owner.(@title == "roomowner");
go();
}
private function initConnection(event:FlexEvent):void{
getXML();
}
private function go():void {
var fmsstring:String = "rtmp://blah.com/appname/" + xinstance;
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
nc.connect(fmsstring);
nc.client = this;
}
protected function onNetStatus(event:NetStatusEvent):void{
trace(event.info.code);
switch(event.info.code){
case "NetConnection.Connect.Success":
publishCamera();
displayPublishingVideo();
chat_broadcastLive();
so = SharedObject.getRemote("message", nc.uri, false);
so.username = xusername;
so.userid = xuserid;
so.userType = xroomowner;
so.addEventListener(SyncEvent.SYNC, soOnSync);
so.client = this;
so.connect(nc);
//so.setProperty("userinfo",{username:xusername, userid:xuserid, userType:xroomowner});
sendBtn.addEventListener(MouseEvent.CLICK, onClickSendBtn);
break;
case "NetConnection.Connect.Closed" :
nc.call("chat.sendMessage", myResponder, xusername + " left the room");
break;
}
}
主目录
application.onAppstart = function(){
this.totalUserCount = 0;
}
application.onConnect = function(client, username, userid, gender, userType, birthday )
{
//userType = so.data.userinfo["userType"];
client.username = username;
client.userid = userid;
client.gender = gender;
client.userType = userType;
client.birthdaye = birthday;
if(userType="viewer"){
this.totalUserCount++;
}
client.chat = chat;
application.acceptConnection(client);
}
application.onDisconnect = function(client){
if(userType="viewer"){
this.totalUserCount--;
}
}
trace("usercount is:" + this.totalUserCount);
使用上面的 main.asc 代码我得到“usercount is undefined”,所以我一定做错了什么。