How to Integrate AS3 Using PHP & MySQL

Written by mark stansberry
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Integrate AS3 Using PHP & MySQL
Build social networks with AS3, PHP and MySQL software packages. (Thomas Northcut/Photodisc/Getty Images)

Central to building of business applications with Adobe Flash is the ability to integrate databases built with MySQL and database communication transfer mechanisms built with PHP and AS3(ActionScript 3, the Flash Programming Language). The ability to integrate these three software building blocks not only gives you what you need to create commercial quality business applications, but also gives you the programming skills that businesses need use to create content management systems, real time transaction systems and social networks.

Skill level:
Challenging

Other People Are Reading

Things you need

  • PHP/MySQL web hosting provider
  • Flash Professional(Versions CS3, CS4 or CS5)
  • Text editor

Show MoreHide

Instructions

  1. 1

    Create one ActionScript 3(AS3) file, one PHP file and one MySQL database table. Use the Actions editor in the Flash program to create the AS3 file, a text editor or Adobe Dreamweaver to create the PHP file and the MySQL program to create the table file.

  2. 2

    Write the first section of the code in the AS3 file such that it establishes a connection to the PHP file. Use the AS3 URLRequest object, the URLRequest method property, the URLLoader object and the URLVariables object to create the required network connection header to send to the PHP file.

  3. 3

    Code the URLRequest object such that its parameter is the name of the PHP file.

  4. 4

    Code the URLVariables such that it contains the contents of at least one variable and its associated value that you created in the AS3 code.

  5. 5

    Attach to the URLLoader object the URLRequest (the PHP file name), the URLVariables and the URLRequestMethod) to form the network connection header that will be directed to the PHP file on your web server.

  6. 6

    Write the code in the PHP file such that it will receive the AS3 variable data sent from the Flash program (through the $_POST superglobal array) and place that variable's data in the first field in the first record(row) of MySQL database table.

  7. 7

    Include in the PHP file script the MySQL connection command with its associated arguments(server name, username, password) so that the MySQL table on your web server can be accessed by the PHP program.

  8. 8

    Write a MySQL INSERT command to enter the variable's data into the MySQL database.Write the code to process or calculate a new value based on the AS3 variable and store that result in in the second field in the same record (or row) that the AS3 variable was saved in.

  9. 9

    Send this PHP variable back to the Flash program with the PHP print command.

  10. 10

    Append to the AS3 file the code required to read and store the variable sent from PHP (from the second field in the MySQL table) and display it.

  11. 11

    Attach an event listener to the URLLoader object that listens for the EVENT.COMPLETE event and activates the AS3 function to read the PHP variable data within the URLLoader data property (URLLoader.data = event.target).

  12. 12

    Write the code to declare a AS3 TextField that will be used to store the MySQL contents transferred and display it on the Flash stage.

  13. 13

    Create your Flash SWF file and then upload the SWF file and the PHP file to the web server you are using to test the program.

Tips and warnings

  • Review the code at the link listed in the Resources' section below to see actual code implementations and application examples that integrate AS3, MySQL and PHP together. Also review any PHP and MySQL documentation and examples your web hosting vendor might have that gives specific instructions on linking to the MySQL databases that have been assigned to your web account.
  • You won't be able to test if you integrated your AS3, PHP and MySQL integration unless your Flash SWF file and your PHP file and your MySQL database table are located on a web server. The web server will have to have PHP and MySQL support in order for the program to work.

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.