Skip to main content
Participant
June 26, 2008
Question

problem of broadcastMsg()

  • June 26, 2008
  • 4 replies
  • 431 views
my english is not good.sorry.
i'm read the Server-Side ActionScript Language Reference for Adobe Flash Media Interactive Server
to find out one Event to use in undermentioned Example





Example

The following server-side code sends a message to the client:

application.broadcastMsg("testMessage", "Hello World");


The following client-side code catches the message and outputs "Hello World":

nc = new NetConnection();
nc.testMessage = function(msg){
trace(msg);
};




it is used good in as2 but in as3 i can't find a addEventListener to receive "testMessage"

who can help me?
    This topic has been closed for replies.

    4 replies

    no21secAuthor
    Participant
    June 27, 2008
    think very much!

    i's running well.
    Participating Frequently
    June 27, 2008
    Here is the complete working code.
    ---------------------------------------------------------------------------
    var nc:NetConnection;
    nc = new NetConnection();

    nc.client = new Object();
    nc.client.testMessage = testMessage;


    nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

    nc.connect("rtmp://localhost/testApp");


    function netStatusHandler(event:NetStatusEvent):void
    {
    var msg:String = event.info.code;
    switch (event.info.code)
    {
    case "NetConnection.Connect.Success":
    trace("Connection Established with the Server");
    break;

    case "NetConnection.Connect.Failed":
    case "NetConnection.Connect.Rejected":
    case "NetConnection.Connect.Closed":
    case "NetConnection.Connect.AppShutdown":
    case "NetConnection.Connect.InvalidApp":
    case "NetStream.Play.StreamNotFound":
    trace("Connection failed with the Server");
    break;
    }
    }

    function testMessage(msg)
    {
    trace("Message from the server is: " + msg);
    }


    ---------------------------------------------------------------------------

    On the server-side, the following code will be helpful for the same
    --------------------------------------------------------------------------------
    application.onConnect = function(client)
    {
    this.acceptConnection(client);
    this.broadcastMsg("testMessage", "Hello World");
    }

    --------------------------------------------------------------------------------
    And, the output for this will be looking something like this:
    -------------------------------------------------------------------
    Connection Established with the Server
    Message from the server is: Hello World
    -----------------------------------------------------------------
    no21secAuthor
    Participant
    June 27, 2008
    error

    1netConnection.client = net Object (); or
    netConnection.client = new Object ();



    2when i use netConnection.client = new Object ();
    error 1120 netConnection is undecided
    Participating Frequently
    June 26, 2008
    Try this:

    netConnection = new NetConnection();
    netConnection.client = net Object ();

    netConnection.client.testMessage = function(msg)
    {
    Trace(msg);
    }