How to Connect to a Database With AS3 Tutorial

Written by mark stansberry
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Connect to a Database With AS3 Tutorial
Connecting AS3 to a database requires you connect software packages together. (Thinkstock/Comstock/Getty Images)

ActionsScript3(AS3) -- a programming language that is a part of the Adobe Flash, the Adobe AIR and the Adobe Flash Builder platforms -- is used not only for programming animations, but also for file and data transfer tasks. One such task is connecting to, retrieving and sending information to a database. With AS3 file and data transfer classes, methods and properties, you can connect your Flash program to a number of different databases. The database -- whether it is a MySQL, a Microsoft Access, or an AIR-generated local SQL database -- requires a different approach to make the connection.

Skill level:
Moderate

Other People Are Reading

Things you need

  • Web hosting provider with PHP, MySQL, ColdFusion and Microsoft Access support.

Show MoreHide

Instructions

  1. 1

    Create one AS3 file in Adobe Flash Builder or an AIR Flash file in the Flash Professional software package.

  2. 2

    Type the "URLRequest" method in the AS3 file and specify its argument to be the file location of the PHP connection file on the Web server. Refer to www.flash-db.com (see Resources) for the exact syntax for requesting access to the PHP file with the AS3 URLRequest method.

  3. 3

    Create a text file to place the PHP connection code that will connect the AS3 file to the database to a MySQL database.

  4. 4

    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 you are accessing 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. Refer to www.flash-db.com (see Resources) for the exact syntax to use for the mySQL connection function.

  1. 1

    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 to be the file location of the ColdFusion connection file on the Web server. Refer to www.flash-db.com (see Resources) for the exact syntax to use with the URLRequest method with a ColdFusion connection file.

  2. 2

    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 datasource name to access the database connection information, the database name you want to connect to, the name of the server the database is on and the username and password required to gain access to the database. Refer to the www.quackit.com (see Resources) for more specifics on using the ColdFusion Administrator.

  3. 3

    Create a text file with a text editor to place the ColdFusion connection code that will connect the AS3 file to the Microsoft Access database. Type the ColdFusion "cfquery,datasource" command in the ColdFusion in this file with the datasource name you specified in the ColdFusion administrator.

  1. 1

    Create one AS3 file in Adobe Flash Builder or an AIR Flash file in the Flash Professional software package.

  2. 2

    Use a SQLConnection object with either the open or openAsync database connection method in the AS3 file to connect to a local SQL database.

  3. 3

    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 www.livedocs.adobe.com website (see Resources) for the actual code and required syntax for connecting to a local SQL database.

Tips and warnings

  • Refer to the AIR, ColdFusion, FlashBuilder(Flex) and ActionScript developer guides and the PHP Web pages listed in the "Resources" section below to obtain the exact specifics on the syntax of the code to use to make connections to other types of databases as well as for specifying other database connection options.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.