Review the remote access database's Application Programming Interface document. Determine the structure of the database's fields and records. Note the name of the fields in the records that you want to access data from (the fields you want to search).
Include in the AS3 code a URLRequest statement that specifies the URL where the remote access database is located, as in:
var remote_database_URL:String= "http://imaginarywebserverlocation.com";
var connect_to_database:URLRequest = new URLRequest();
connect_to_database.URL = remote_database_URL
This code instructs Flash to connect to a remote access database server at the fictitious Web page named "http://imaginarywebserverlocation.com." The string variable, remote_database_URL, is used to store the URL address. The URLRequest method uses the URL address through the "URL" property to specify the Web page where the database is located.
Include in your connection program, AS3 code that will specify the type of data access method to use (GET or POST). Use POST if you are concerned someone might want to intercept or listen to your remote access database requests.
connect_to_database.method = URLRequestMethod.GET;
Include in your connection program, AS3 code that will send a request to the remote access database server to search a field in the database for a specific keyword.
var rain:String = "80"
connect_to_database.data = "Probability of Rain=" + rain;
In this code, the data property of the URLRequest object is used to store the field and keyword request to be sent from Flash to the remote access database. The code specifies that the URLRequest object request to search the Probability of Rain field in the remote access database and to search for all records in the database that have 80 (for 80 percent chance of rain) in them.
Include in your connection program, the AS3 code that will send the URLRequest object (header) to the remote access database server (to search in the specific database field for the keyword as specified in the URLRequest data property).
var sendRequest:URLLoader = new URLLoader(connect_to_database);
Include in your connection program, the AS3 code that will detect whether or not the remote access database server responded to the sendRequest successfully or not.
sendRequest.addEventListener(Event.COMPLETE, finishedLoading);
sendRequest.addEventListener(IOErrorEvent.IO_ERROR, didnotrespond);
}
function finishedLoading(event:Event):void {
var serverResponse:URLLoader = URLLoader(event.target);
var serverResponse:XML = XML(serverResponse.data);
trace("server successfully connected");
}
function didnotrespond(event:Event):void {
trace("Failed to Connect Correctly for the Request Sent");
}
This code attempts to load the servers response (the database search results that the server sends back) into an XML file within Flash. If the requested response data from the server's database is received, a success message is displayed. If the connection is not made and the the response XML file is not loaded, a failure message is displayed.