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:
Things you need
- PHP/MySQL web hosting provider
- Flash Professional(Versions CS3, CS4 or CS5)
- Text editor
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.
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.
Code the URLRequest object such that its parameter is the name of the PHP file.
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.
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.
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.
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.
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.
Send this PHP variable back to the Flash program with the PHP print command.
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.
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).
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.
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.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for