The Connection class is a collection of methods that helps you create and use Flash Remoting connections to services.
Note: The Connection class replaces the NetConnection class, which is no longer available. Macromedia recommends that you use the Service class to connect to remote services.
Note: You cannot use the PendingCall or RelayResponder classes with the Connection class to handle results or fault conditions that are returned from service functions. For information on how to handle results and fault conditions with the Connection class, see Appendix A, Using NetServices and Connection Classes.
You can import the Connection class using the following import statement:
import mx.remoting.Connect;
| Methods | |
| addHeader(
name:
String, mustUnderstand:
Boolean, obj:
Object)
: VoidNote: You do not normally use this method in Flash Remoting; it is used by the setCredentials method. |
| call(
remoteMethod:
String, resultObject:
Object, args:
Array)
: VoidInvokes a command or method on the server. |
| clone(
)
: ConnectionCreates a new Connection object that is a clone of the current Connection object except that it does not have the headers. |
| close(
)
: VoidMakes the URL previously specified with the connect() method into a null value, thereby removing the connection configuration for the remote gateway. |
| connect(
url:
String)
: BooleanDefines the Flash Remoting URL that is used by Flash Remoting service function calls. |
| getDebugConfig(
)
: NetDebugConfigRetrieves the NetDebug object of this Connection object`s debug-subscribed events. |
| getDebugId(
)
: StringRetrieves the Connection object`s debug identifier, previously set using the setDebugId() method. |
| getService(
serviceName:
String, client:
Object)
: NetServiceProxyCreates a Flash Remoting NetServiceProxy object, which allows access to application server functions. |
| setCredentials(
userId:
String, password:
String)
: VoidSubmits a set of credentials that authenticates the user to the server. |
| setDebugId(
id:
String)
: VoidSets this Connection object`s debug identifier. |
| trace(
traceObj:
Object)
: VoidSends a client trace message associated with the Connection object to the NetConnection Debugger (NCD). |
| Properties | |
static | version:
String Component version. |
| Method Detail |
addHeader(
name:
String, mustUnderstand:
Boolean, obj:
Object)
: Void
Parameters
name:
String - A string that triggers processing and that both Flash Remoting and the application server recognize.
mustUnderstand:
Boolean - A Boolean value that specifies whether the server must understand and process this header prior to handling any of the following headers or messages.
obj:
Object - Any ActionScript object.
See Also
mx.remoting.Connection.setCredentials
call(
remoteMethod:
String, resultObject:
Object, args:
Array)
: Void
Parameters
remoteMethod:
String - A string in the form of serviceName.methodName where the interpretation of serviceName depends on your Flash Remoting MX application and the application server that you are using. It is the name of the service to which you are connecting.
resultObject:
Object - A responder object that specifies the result and fault handling methods for this service function call. Pass a null value for this parameter if you do not need it. The responder must have onResult and onStatus functions.
args:
Array - Optional. Any number of additional parameters that are required by the method that is being called.
categoryList and a status message is displayed in a special status bar called statusBar:
import mx.remoting.RecordSet;
import mx.remoting.Connection;
import com.mycompany.crm.utils.DisplayHandler;
var con1:Connection = new Connection();
con1.connect("http://examples.macromedia.com/flashservices/gateway/");
con1.call("petmarket.api.catalogservice.getCategories", new DisplayHandler( statusBar, categoryList ), {locale:"en_US"});
The following class file DisplayHandler.as should be located in the com.mycompany.crm.utils classpath directory:
import mx.controls.TextInput;
import mx.controls.List;
import mx.remoting.RecordSet;
class com.mycompany.crm.utils.DisplayHandler extends Object {
function DisplayHandler( disp:TextInput, lst:List ) {
super();
_statusBar = disp;
_dispList = lst;
}
function onResult( result:RecordSet ):Void {
_dispList.dataProvider = result;
_statusBar.text = "Got Data - " + result.length + " Record" + (result.length>1?"s":"");
}
function onStatus(stat:Object):Void {
_statusBar.text = "DataCallFailed-" + stat.code;
}
private var _statusBar:TextInput;
private var _dispList:List;
}
See Also
mx.remoting.Service.Service
mx.rpc.RelayResponder
clone(
)
: Connection
setCredentials() method to authenticate the user.
Note: Macromedia recommends that you use the Service object to establish a gateway connection and access remote service functions.
Returns
A connection object that is a clone of the current connection but without headers.
import mx.remoting.Connection;
import mx.remoting.Service;
import mx.rpc.RelayResponder;
mx.remoting.debug.NetDebug.initialize();
var con1:Connection = new Connection();
con1.setDebugId( "CategoryData - con1" );
var catDataResp:RelayResponder = new RelayResponder( this, "onCatData", "onCatDataFault" );
con1.connect( "http://examples.macromedia.com/flashservices/gateway/" );
var cat:Service = new Service( null, null, "catalogservice", con1, catDataResp );
// we want a new connection for this service to avoid batching with a
// different debug id
var con2:Connection = con1.clone();
con2.setDebugId( "CategoryData - con2" );
var cat2DataResp:RelayResponder = new RelayResponder( this, "onCatData", "onCatDataFault" );
var categories:Service = new Service( null, null, "catalogservice", con2, cat2DataResp );
See Also
mx.remoting.Connection.close
mx.remoting.Connection.connect
mx.remoting.Connection.setCredentials
close(
)
: Void
connect() method into a null value, thereby removing the connection configuration for the remote gateway. Subsequent attempts to call Flash Remoting MX using the Connection object fail. After using the close() method, you call connect() to define a new URL.
Example
categoryList and a status message is displayed in a special status bar called statusBar:
import mx.remoting.RecordSet;
import mx.remoting.Connection;
import com.mycompany.crm.utils.DisplayHandler;
var con1:Connection = new Connection();
con1.connect("http://examples.macromedia.com/flashservices/gateway/");
con1.call("petmarket.api.catalogservice.getCategories", new DisplayHandler( statusBar, categoryList ), {locale:"en_US"});
The following is the class file DisplayHandler.as that should be located in the com.mycompany.crm.utils classpath directory:
import mx.controls.TextInput;
import mx.controls.List;
import mx.remoting.RecordSet;
class com.mycompany.crm.utils.DisplayHandler extends Object {
function DisplayHandler( disp:TextInput, lst:List ) {
super();
_statusBar = disp;
_dispList = lst;
}
function onResult( result:RecordSet ):Void {
_dispList.dataProvider = result;
_statusBar.text = "Got Data - " + result.length + " Record" + (result.length>1?"s":"");
}
function onStatus(stat:Object):Void {
_statusBar.text = "DataCallFailed-" + stat.code;
}
private var _statusBar:TextInput;
private var _dispList:List;
}
See Also
mx.remoting.Connection.connect
mx.remoting.Connection.clone
connect(
url:
String)
: Boolean
Parameters
url:
String - The Flash Remoting URL [protocol://] host [:port] /appName The value of appName depends on the type of gateway and the configuration of Flash Remoting. For more information, see "Establishing the Flash Remoting gateway connection" on page 36. If you omit protocol://, Flash assumes you want to connect to an application server using the nonsecure HTTP protocol. The other acceptable value for protocol is https. For example, the following URLs are formatted correctly:
Returns
A Boolean value of true if the protocol part of the URL (the http: or https:) is valid; false otherwise.
categoryList, and a status message is displayed in a special status bar called statusBar:
import mx.remoting.RecordSet;
import mx.remoting.Connection;
import com.mycompany.crm.utils.DisplayHandler;
var con1:Connection = new Connection();
con1.connect("http://examples.macromedia.com/flashservices/gateway/");
con1.call("petmarket.api.catalogservice.getCategories", new DisplayHandler( statusBar, categoryList ), {locale:"en_US"});
con1.close();
The following is the class file DisplayHandler.as that should be located in the com.mycompany.crm.utils classpath directory:
import mx.controls.TextInput;
import mx.controls.List;
import mx.remoting.RecordSet;
class com.mycompany.crm.utils.DisplayHandler extends Object {
function DisplayHandler( disp:TextInput, lst:List ) {
super();
_statusBar = disp;
_dispList = lst;
}
function onResult( result:RecordSet ):Void {
_dispList.dataProvider = result;
_statusBar.text = "Got Data - " + result.length + " Record" + (result.length>1?"s":"");
}
function onStatus(stat:Object):Void {
_statusBar.text = "DataCallFailed-" + stat.code;
}
private var _statusBar:TextInput;
private var _dispList:List;
}
See Also
mx.remoting.Connection.close
mx.remoting.Connection.clone
getDebugConfig(
)
: NetDebugConfig
NetDebug.initialize() method.
For information on how to invoke and use the NetConnection Debugger, see The NetConnection Debugger.
Returns
A NetDebugConfig object.
con1 and sets the httpheaders, amf, and amfheaders options:
import mx.remoting.debug.NetDebugConfig;
import mx.remoting.Connection;
var con1:Connection = new Connection();
var config:NetDebugConfig = con1.getDebugConfig();
// the following settings allow http headers, amf information, and amf headers
// to be displayed in the NCD.
config.app_server.httpheaders = true;
config.app_server.amf = true;
config.app_server.amfheaders = true;
See Also
mx.remoting.Connection.getDebugId
mx.remoting.Connection.setDebugId
mx.remoting.Connection.trace
mx.remoting.debug.NetDebug.initialize
mx.remoting.debug.NetDebug.trace
getDebugId(
)
: String
setDebugId() method.
Note: This method only returns a value if the application previously called the NetDebug.initialize() method.
For information on how to invoke and use the NetConnection Debugger, see Chapter 5, "The NetConnection Debugger," on page 85.
Returns
A string that is the Connection object`s debug ID.
con1 to the value "myDebugId". A call is then made to a Remoting service. Finally the debug ID is traced to the Output panel. You can use the filter feature in the NetConnection Debugger to show transactions only from that debug ID:
import mx.remoting.RecordSet;
import mx.remoting.Connection;
import mx.remoting.debug.NetDebug;
import com.mycompany.crm.utils.DisplayHandler;
NetDebug.initialize();
var con1:Connection = new Connection();
con1.setDebugId("myDebugId");
con1.connect("http://examples.macromedia.com/flashservices/gateway/");
con1.call("petmarket.api.catalogservice.getCategories", new DisplayHandler( statusBar, categoryList), {locale:"en_US"});
trace(con1.getDebugId());
con1.close();
The following is the class file DisplayHandler.as that should be located in the com.mycompany.crm.utils classpath directory:
import mx.controls.TextInput;
import mx.controls.List;
import mx.remoting.RecordSet;
class com.mycompany.crm.utils.DisplayHandler extends Object {
function DisplayHandler( disp:TextInput, lst:List ) {
super();
_statusBar = disp;
_dispList = lst;
}
function onResult( result:mx.remoting.RecordSet ):Void {
_dispList.dataProvider = result;
_statusBar.text = "Got Data - " + result.length + " Record" + (result.length>1?"s":"");
}
function onStatus(stat:Object):Void {
_statusBar.text = "DataCallFailed-" + stat.code;
}
private var _statusBar:TextInput;
private var _dispList:List;
}
See Also
mx.remoting.Connection.getDebugConfig
mx.remoting.Connection.setDebugId
mx.remoting.Connection.trace
mx.remoting.debug.NetDebug.initialize
mx.remoting.debug.NetDebug.trace
getService(
serviceName:
String, client:
Object)
: NetServiceProxy
Parameters
serviceName:
String - A string containing the name of the service to call.
client:
Object - An object responder for method call result and fault outcomes.
Returns
A NetServiceProxy object that is an instance of the proxy for the network client of the specified local client and service name.
getService() method of the Connection object named con1 to create a NetServiceProxy object. The NetServiceProxy object is then used to call the service methods:
import mx.remoting.Connection;
import mx.remoting.NetServiceProxy;
getCategories_Result = function( results: Object ):Void {
trace("Got Data - " + results.length + " Record" + (results.length>1?"s":""));
}
getCategories_Status = function( stat: Object ):Void {
trace("DataCallFailed-" + stat.code);
}
var con1:Connection = new Connection();
con1.connect("http://examples.macromedia.com/flashservices/gateway/");
var catalogService:NetServiceProxy =
con1.getService("petmarket.api.catalogservice", this );
catalogService.getCategories({locale:"en_US"});
See Also
mx.remoting.Service.Service
setCredentials(
userId:
String, password:
String)
: Void
setCredentials() method more than once.
If the server does not authenticate the user, setCredentials() returns an error in the FaultEvent object.
Note: This method only works with ColdFusion MX and JRun4 servers.
For more information about authenticating a user, see Authenticating a user to the application server and Using NetServices and Connection Classes.
Parameters
userId:
String - A string containing the user ID.
password:
String - A string containing the user password.
con1 and then calls the getCategories() method. The credentials are then changed and a call is made to the getProducts() method for all products with a categoryoid value of 5:
import mx.remoting.Connection;
import mx.remoting.NetServiceProxy;
function getCategories_Result ( results: Object ):Void {
trace("Got Categories - " + results.length + " Record" + (results.length>1?"s":""));
}
function getCategories_Status ( stat: Object ):Void {
trace("CategoriesCallFailed-" + stat.code);
}
function getProducts_Result ( results: Object ):Void {
trace("Got Products - " + results.length + " Record" + (results.length>1?"s":""));
}
function getProducts_Status ( stat: Object ):Void {
trace("ProductCallFailed-" + stat.code);
}
var con1:Connection = new Connection();
con1.connect("http://examples.macromedia.com/flashservices/gateway/");
var catalogService:NetServiceProxy = con1.getService( "petmarket.api.catalogservice", this );
con1.setCredentials("joe", "SeCrEt");
catalogService.getCategories({locale:"en_US"});
con1.setCredentials("kelly", "valleygirl");
catalogService.getProducts({categoryoid:5});
con1.close();
See Also
mx.remoting.Connection.connect
mx.remoting.Connection.clone
mx.rpc.FaultEvent
setDebugId(
id:
String)
: Void
initialize() method.
For information on how to invoke and use the NetConnection Debugger, see The NetConnection Debugger.
Parameters
id:
String - A string that is the debug ID for the Connection object. This value will show up in the NCD (NetConnection Debugger) to identify this connection.
con1 to the value "myDebugId". A call is then made to a Remoting service. Finally the debug ID is traced to the Output panel. You can use the filter feature in the NetConnection Debugger to show transactions only from that debug ID. The results are displayed in a list called categoryList and a status message is displayed in a special status bar called statusBar:
import mx.remoting.RecordSet;
import mx.remoting.Connection;
import mx.remoting.debug.NetDebug;
import com.mycompany.crm.utils.DisplayHandler;
NetDebug.initialize();
var con1:Connection = new Connection();
con1.setDebugId("myDebugId");
con1.connect("http://examples.macromedia.com/flashservices/gateway/");
con1.call("petmarket.api.catalogservice.getCategories", new DisplayHandler( statusBar, trace(con1.getDebugId())), {locale:"en_US"});
con1.close();
The following is the class file DisplayHandler.as that should be located in the com.mycompany.crm.utils classpath directory:
import mx.controls.TextInput;
import mx.controls.List;
import mx.remoting.RecordSet;
class com.mycompany.crm.utils.DisplayHandler extends Object {
function DisplayHandler( disp:TextInput, lst:List ) {
super();
_statusBar = disp;
_dispList = lst;
}
function onResult( result:RecordSet ):Void {
_dispList.dataProvider = result;
_statusBar.text = "Got Data - " + result.length + " Record" + (result.length>1?"s":"");
}
function onStatus(stat:Object):Void {
_statusBar.text = "DataCallFailed-" + stat.code;
}
private var _statusBar:TextInput;
private var _dispList:List;
}
See Also
mx.remoting.Connection.getDebugConfig
mx.remoting.Connection.getDebugId
mx.remoting.Connection.trace
mx.remoting.debug.NetDebug.initialize
mx.remoting.debug.NetDebug.trace
trace(
traceObj:
Object)
: Void
NetDebug.initialize() method.
For information on how to invoke and use the NetConnection Debugger, see The NetConnection Debugger.
Parameters
traceObj:
Object - An ActionScript object that contains the trace message to send to the NetConnection Debugger.
myDebugId". Before calling a method, Connection.trace() is used to send a message to the NetConnection Debugger. The results are displayed in a list called categoryList and a status message is displayed in a special status bar called statusBar:
import mx.remoting.RecordSet;
import mx.remoting.Connection;
import mx.remoting.debug.NetDebug;
import com.mycompany.crm.utils.DisplayHandler;
NetDebug.initialize();
var con1:Connection = new Connection();
con1.setDebugId("myDebugId");
con1.connect("http://examples.macromedia.com/flashservices/gateway/");
con1.trace({level:"debug", message:"anonymous message"});
con1.call("petmarket.api.catalogservice.getCategories", new DisplayHandler( statusBar, categoryList ), {locale:"en_US"});
con1.close();
The following is the class file DisplayHandler.as that should be located in the com.mycompany.crm.utils classpath directory:
import mx.controls.TextInput;
import mx.controls.List;
import mx.remoting.RecordSet;
class com.mycompany.crm.utils.DisplayHandler extends Object {
function DisplayHandler( disp:TextInput, lst:List ) {
super();
_statusBar = disp;
_dispList = lst;
}
function onResult( result:RecordSet ):Void {
_dispList.dataProvider = result;
_statusBar.text = "Got Data - " + result.length + " Record" + (result.length>1?"s":"");
}
function onStatus(stat:Object):Void {
_statusBar.text = "DataCallFailed-" + stat.code;
}
private var _statusBar:TextInput;
private var _dispList:List;
}
See Also
mx.remoting.Connection.getDebugConfig
mx.remoting.Connection.getDebugId
mx.remoting.Connection.setDebugId
mx.remoting.debug.NetDebug.initialize
mx.remoting.debug.NetDebug.trace
| Property Detail |
static
version:
String
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flashremoting/mx2004/actionscript_api_reference/mx/remoting/Connection.html