How to Connect to a Database With AS3
Adobe's Actions Script 3 programming language is designed for file and data transfer tasks, including retrieving and sending information to a database. Use AS3 file and data transfer classes, methods and properties to connect your Adobe Flash program to multiple databases. Different database types -- for example, MySQL, Microsoft Access or an AIR-generated local SQL database -- require different connection methods.
- Web hosting provider with PHP, MySQL, ColdFusion and Microsoft Access support.
1 MySQL Databases
2 Create one AS3 file
Create one AS3 file in Adobe Flash Builder or an AIR Flash file in the Flash Professional software package.
3 Type
Type the "URLRequest" method in the AS3 file and specify its argument as the file location of the PHP connection file on the Web server.
4 Create a text file
Create a text file to place the PHP connection code that connects the AS3 file to the database to a MySQL database.
5 Use the mySQLconnect function
Use the "mySQLconnect" function in the PHP connection file for connecting to the MySQL database with AS3. Specify the host server name, your user name and your password for the MySQL database as the arguments in the PHP "mysql_connect" function. Use the PHP "mysql_select_db" function to select the specific MySQL database with the PHP variable you used to store the "mysql_connect" function.
6 Microsoft Access
7 Create one AS3 file-2
Create one AS3 file in Adobe Flash Builder or an AIR Flash file in the Flash Professional software package. Type the "URLRequest" method in the AS3 file, and specify its argument as the file location of the ColdFusion connection file on the Web server.
8 Set the ColdFusion database connection information
Set the ColdFusion database connection information and the type of database to connect to with the ColdFusion Administrator. Click the Add New Data option, and then enter Microsoft Access for the driver type. Click Add. Enter a data source name to access the database connection information, the database name you want to connect to, the name of the database server and the login credentials.
9 Create a text file with a text editor
Create a text file with a text editor to place the ColdFusion connection code that connects the AS3 file to the Microsoft Access database. Type the ColdFusion "cfquery,datasource" command in the file with the datasource name you specified in the ColdFusion administrator.
10 SQL Databases
11 Create one AS3 file-3
Create one AS3 file in Adobe Flash Builder or an AIR Flash file in the Flash Professional software package.
12 Use an SQLConnection object
Use an SQLConnection object with either the open or openAsync database connection method in the AS3 file to connect to a local SQL database.
13 Use the name
Use the name of the local SQL database, stored in a file object, with the "resolvePath" method as the argument for the SQLConnection object.
- Refer to the AIR, ColdFusion, FlashBuilder(Flex) and ActionScript developer guides and the PHP Web pages section below to obtain the exact code syntax to use to make connections to other database types.