View comments | RSS feed

Application.broadcastMsg()

Availability

Flash Media Server 2.

Usage

application.broadcastMsg(cmd [, p1, p2, ..., pN]) 

Parameters

cmd A string; a message to broadcast.

p1 A string; additional messages.

Returns

Nothing.

Description

Method; broadcasts a message to all connected clients.

This method is equivalent to looping through the Application.clients array and calling Client.call() on each individual client, but is more efficient (especially for large number of connected clients). The only difference is that you can't specify a response object when you call broadcastMsg(), otherwise, the syntax is the same.

Shared objects can handle broadcast messages with the SharedObject.handlerName property.

Example

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

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

The following client-side code catches the message and prints it in the Output panel:

nc = new NetConnection();
nc.handlerName = function(msg) { trace(msg); } 
// traces out "Hello World"

See also

SharedObject.handlerName


Comments


BcisR_D said on Nov 18, 2009 at 10:15 AM :
Client side for Action Script 3 is

nc.client=new Object();
nc.handlerName = function(msg) { trace(msg); }
jody_b said on Nov 18, 2009 at 12:19 PM :
Thanks for pointing this out, BcisR_D. You're right -- in AS3 callback handlers must be defined on an object pointed to by the NetConnection.client property.

There are a few ways you can do handle callbacks from the server:

public function init():void {
...
ncClient = new Object();
nc.client = ncClient;
ncClient.handlerName = nc_handlerName;
...
}

private function nc_handlerName(msg:String):void{
debug(msg);
}

(The debug function prints to a TextArea in the app.)

Or, you can assign nc.client = this: and define a public callback function:

public function handlerName(msg:String):void {
debug(msg);
}

HTH,
Jody

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/fms/2/docs/00000643.html