0

I've searched through Google, FMS Guru and a ton of Adobe developer tutorials. I'm a little confused as how to send variables as parameters in the sharedobject or the client object from the client side so I can grab & process the variables on the server side from within the main.asc file.

For example how would I send username, userid, gender, usertype and birthday variables to the main.asc file using AS3 from the created SWF?

From 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;

                }
            }

Main.asc

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);

Using the main.asc code above I get "usercount is undefined", so I must be doing something wrong.

Patriotec
  • 1,104
  • 4
  • 22
  • 43

1 Answers1

1

At least one of your problems is your assigning the value "viewer" to your userType var instead of evaluating it. eg

if(userType="viewer")

should be

if(userType == "viewer")

Also, your trace statement is likely running before you're application onStart(), so indeed your variable is undefined at that point.

In your client side code, you need to pass the arguments in the connect() function on the net connection after the connection string, so in case it would be like this:

nc.connect(fmsstring, username, userid, gender, userType, birthday);
BadFeelingAboutThis
  • 14,445
  • 2
  • 33
  • 40
  • I fixed the "==" issue. I know I can use application.clients.length; in main.asc to get all connected clients, but may want to filter by another variable. How do I send from the AS3 code in the mxml the needed variable using the existing code I have? – Patriotec Aug 09 '12 at 01:03
  • Thanks. I tried this the other night, but it didn't work because I wasn't loading the XML correctly in this example: http://stackoverflow.com/questions/11855918/as3-concatenate-rtmp-connection-string-from-xml-between-two-functions – Patriotec Aug 09 '12 at 12:34