application.redirectConnection(clientObj, url[, description[, errorObj]])
Rejects a connection and provides a redirect URL. You must write logic in the NetConnection.onStatus() handler that detects redirection and passes the new connection URL to the NetConnection.connect() method.
When this method is called, NetConnection.onStatus() is invoked on the client and passed an information object with the following values:
|
Property |
Value |
|---|---|
|
info.code |
"NetConnection.Connect.Rejected" |
|
info.description |
The value passed in the description parameter; if no value is passed in the parameter, the default value is "Connection failed" |
|
info.ex.code |
302 |
|
info.ex.redirect |
The new connection URL |
|
info.level |
"Error" |
Flash Media Interactive Server 3 and Flash Media Development Server 3
clientObj A Client object specifying a client to reject.
url A string specifying the new connection URL.
description A string that lets you provide more information when a connection is redirected.
errorObj An object of any type that is sent to the client, explaining the reason for rejection. The errorObj object is available in client-side scripts as the application property of the information object that is passed to the NetConnection.onStatus() call when the connection is rejected.
The following example is server-side code:
application.onConnect = function(clientObj, count){
var err = new Object();
err.message = "This is being rejected";
err.message2 = "This is the second message. with number description";
if (count == 1){
redirectURI = "rtmp://www.example.com/redirected/fromScript";
redirectDescription = "this is being rejected via Server Side Script.";
}
else if (count == 2){
redirectURI = "rtmp://www.example2.com/redirected/fromScript";
redirectDescription = "this is being rejected via Server Side Script.";
}
application.redirectConnection(clientObj, redirectURI, redirectDescription, err);
}
The following example is client-side ActionScript 3.0 code:
var theConnection:NetConnection;
var theConnection2:NetConnection;
var client:Object = new Object();
function init():void{
connect_button.label = "Connect";
disconnect_button.label = "Disconnect";
connect_button.addEventListener(MouseEvent.CLICK, buttonHandler);
disconnect_button.addEventListener(MouseEvent.CLICK, buttonHandler);
}
function buttonHandler(event:MouseEvent){
switch (event.target){
case connect_button :
doConnect();
break;
case disconnect_button :
disConnect();
break;
}
}
function doConnect(){
makeConnection(theURI.text);
}
function disConnect(){
theConnection.close();
}to
function makeConnection(uri:String){
if (theConnection){
theConnection.close();
}
theConnection = new NetConnection();
theConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
theConnection.client = client;
theConnection.connect(uri);
}
function makeConnection2(uri:String){
if (theConnection2){
theConnection2.close();
}
theConnection2 = new NetConnection();
theConnection2.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
theConnection2.client = client;
theConnection2.connect(uri);
}
function netStatusHandler(event:NetStatusEvent):void{
//Check the Redirect code and make connection to redirect URI if appropriate.
try{
if (event.info.ex.code == 302){
var redirectURI:String;
redirectURI = event.info.ex.redirect;
if (redirectURI.charCodeAt(redirectURI.length-1) == 13){
redirectURI = redirectURI.slice(0,(redirectURI.length-1));
}
makeConnection2(redirectURI);
}
}
}
init();