Skip to main content
Known Participant
September 30, 2009
Answered

Can you pass objects (not strings) to application.onConnect()?

  • September 30, 2009
  • 1 reply
  • 1319 views

The documentation on parameters for application.onConnect() is below.  It can take a Client "object" but is ambiguous about the optional parameters (strings vs objects).  I'm guessing just strings?

I have a user value object with a few pieces of info in it that I pass around client side and would like the server to add it to its list of users (usersSO).  I'm guessing I'll have to send it up in pieces and recreate it somehow on the server?

Parameters

clientObj
A Client object. This object contains information about the client that is connecting to the application.
p1 ..., pN
Optional parameters passed to the application.onConnect() handler from the client-side NetConnection.connect()







    This topic has been closed for replies.
    Correct answer

    Yeah, an instance of the valueObject class.

    That's ok.  I'm currently passing the data up in pieces (strings) and creating a user object on the server.  All is working.  But, again, I'm looking to conform to, or establish, best practices.  I'm not sure if I should be constructing objects differently client side in light of FMS or if the way I'm doing things is in line with what others are doing.


    Yeah... you need to think actionscript 1 when you're passing arguments to FMS for processing. No classes, no collections.

    There's been noise about AS3 support in a future release of FMS, but I'm thinking that at this point it's just that... noise.

    1 reply

    September 30, 2009

    You can use an object as the value of an argument. Same goes for arrays, numbers, dates, etc.

    The object structure will be maintained, so the object will look the same on the server side as it does on the client side.

    Keep in mind that not all AS datatypes are supported on the server side. You can send data of unsupported types from client to server to client, but you can't do anything with the unsupported data on the server side. Anything AS3 specific is not supported (no arrayCollections or anything like that), and there is no server side equivalent for anything displayObject

    The Client object is not an object sent from the client, it refers to the object FMS creates to represent the client. So, if on the client side you do:

    connect("rtmp://blah", {one:1, two:2, three:3});

    On the server side you'd have

    application.onConnect = function(client, arg1Obj){

    trace(argObj.one);

    trace(argObj.two);

    trace(argObj.three);

    }

    The console would trace:

    1

    2

    3

    Known Participant
    September 30, 2009

    An instance of this does not remain intact when I pass it.

    package classes.valueObjects
    {
        public class User
        {
            public var userName:String;
            public var userType:String;
           
            public function User(un:String, ut:String)
            {
                userName = un;
                userType = ut;
            }

        }
    }

    Just a couple of strings.  The server doesn't know what it is though.

    October 1, 2009

    What are you passing as the argument in the NetConnection.connect constructor... an instance of the valueObjects class? If that's the case, it's a no-go. FMS can't handle a class object.