
34
Server-Side ActionScript Language Reference
If you don’t use the Flash Media Server components framework, you can execute code in the
application.onConnect
handler after accepting or rejecting the connection. When you use
the components framework, however, any code you want to execute after the connection is
accepted or rejected must be placed in the event handlers
application.onConnectAccept
and
application.onConnectReject
. This architecture allows all the components to decide
whether a connection is accepted or rejected.
Example
The following example is the client-side code you can use for an application:
nc = new NetConnection();
nc.connect("rtmp:/test","jlopes");
nc.onStatus = function(info) {
trace(info.code);
};
nc.doSomething = function(){
trace("doSomething called!");
}
The following example is server-side code you can include in the main.asc file:
// When using components, always load components.asc.
load("components.asc");
application.onConnect = function(client, username){
trace("onConnect called");
gFrameworkFC.getClientGlobals(client).username = username;
if (username == "hacker") {
application.rejectConnection(client);
}
else {
application.acceptConnection(client);
}
}
// Code is in onConnectAccept and onConnectReject statements
// because components are used.
application.onConnectAccept = function(client, username){
trace("Connection accepted for "+username);
client.call("doSomething",null);
}
application.onConnectReject = function(client, username){
trace("Connection rejected for "+username);
}