PHP Flash Integration Tutorial
PHP, also know as PHP Hypertext Processing, is a computer language that was originally designed for the development of computer programs for Web pages. Today it is an essential element for building a wide variety of Web-based business applications. The integration of Flash and PHP into a Web page gives programmers the ability to easily develop business applications that feature animation, sound, and games. Once you learn how to integrate PHP with Flash, you will have the basic skill necessary to create applications such as social networks complete with everything from games to personalized office automation software.
Things You'll Need
- Adobe Flash Professional (Versions CS3, CS4, and CS5) or Online Flash ActionScript Interpreter
- PHP Software or Online PHP Interpreter
Instructions
-
-
1
Determine which variables you will send from your Flash program to your PHP program, then determine which variables to send from your PHP program to your Flash program. Name your PHP file so that Flash will know where to send the variables.
-
2
Write the code for the transfer of variables from your Flash program to your PHP program. Include in this code the Flash ActionScript code that will request access to the PHP file (URLRequest with the PHP file name), the method of sending the variables to the PHP file (URLRequest.method=POST), the variables to send (URLVariables) and the Flash loader (URLLoader) that will send the file name, the sending method and the variables set with the URLRequest, URLRequestMethod and URLVariables statements.
-
-
3
Write the ActionScript code (Flash's programming language) that will receive the variables' values sent from the PHP file to the Flash program. Use an addEventListener event handler attached to the URLLoader and ActionScript text variables to detect when that the PHP variables have been sent. Store the PHP variables sent back from the PHP program. Use the event, EVENT.COMPLETE, in the addEventListener method to detect that the PHP program has sent the values of the variables. Use the sent variable values in the Flash file from the event target of the URLLoader to access and store the variable values sent back from the PHP file.
-
4
Write the PHP code to store the variables the PHP program receives from the Flash program (stored in the global variables of the PHP $_POST array within the PHP file). Next, write the code or PHP function to process or perform calculations with the variables within the $_POST array. Finally, write the PHP code to send back the PHP variables' values to the Flash program (using the PHP print command).
-
1
Tips & Warnings
The Flash methods in the ActionScript file to access data and functions in a PHP file are used to write a header that supplies the Web server with the ActionScript variable names and their associated numerical or text values, the name of the PHP file you want to access and the method you want to use to access the PHP file (either GET or POST). The PHP method in the PHP file to receive variable names and their associated values requires that you read the PHP $POST array variables (the PHP super global array that receives variables and their names). Sending data back to Flash from PHP requires that you use the PHP print statement in the PHP file. Receiving data from the PHP file in Flash requires that you read the data in the event target of the URLLoader event listener. See the Resource titled "Two Way Flash + PHP Communication" in the Resources section below to see the basic PHP and ActionScript code implementation for integrating PHP and Flash together.
Your PHP file and Flash SWF file need to be located on a Web server in order to test if the Flash and PHP program have been integrated. These files should be located in the same file directory.
References
Resources
- Photo Credit Comstock Images/Comstock/Getty Images