1 / 15

ActionScript & PHP

ActionScript & PHP. GET vs POST:. Two ways to transfer data between Flash and server-side scripts: GET or POST Using GET - concatenates variable name/values into the URL http://www.wdim.aiwsites.com/ info.php ? firstname = Johny & lastname = Smith

harmon
Download Presentation

ActionScript & PHP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ActionScript & PHP

  2. GET vs POST: Two ways to transfer data between Flash and server-side scripts: GET or POST • Using GET - concatenates variable name/values into the URL • http://www.wdim.aiwsites.com/info.php?firstname=Johny&lastname=Smith • This method is not very secure and also has a 1024-character limitation • Using POST, the data is contained in the header of the HTTP request • POST does not have a character limit

  3. Variables out of PHP • Flash can receive data in name-value pairs (variables in the format of name=value). If there is more than one pair then each name-value pair is separated by an ampersand, and so a typical string of name-value pairs may look like this: &name1=Neil&location1=Bristol&name2=Justin&location2=London& • The final ampersand is optional.

  4. Sending back to Flash • If Flash is expecting a value to be returned then it will pick up this returned value and use it in the Flash movie. • Use the PHP language construct echo to output a value from PHP, • Echo it in "name-value pair" format so that Flash can understand it.

  5. Sending back to Flash • PHP can also output data in XML format • Echo it in XML format so that Flash can use its XML methods to parse it. • Save the data to an XML file so that Flash can use its XML methods to parse it.

  6. MySQL Interaction Utilizing MySQL and PHP allows Flash to display and retrieve dynamic data, among other things

  7. Flash – PHP – MySQL Interaction A file is accessed by a browser Webpage/SWF When PHP processing/output is complete, Display data in flash Flash Interaction PHP PHP MySQL

  8. MySQL - Flash • MySQL communicates with PHP (or other language) that can format data into a format that Flash understands. • You do not change how PHP connects to or queries the MySQL database, instead you change how PHP outputs the returned data. • Flash variables format or XML format • You treat the variables received from Flash the same as you would treat GET or POSt variables received from an HTML page or form. • Make

  9. PHP Output • XML output from MySQL example • http://onaje.com/content/transforming-dynamically-generated-xml-html • Flash Vars format … connect to DB, select rows print <?xml version="1.0"?>';print '<result>';while($row = mysql_fetch_array($query)){print "<row>";… decide how to format/output retrieved rowsprint "</row>";}print "</result>";

  10. Example: Poll • Flash MySQL Poll • Have visitors answer a simple poll of a few questions about your project. • On frame/In Movie that displays media, have a button that records the visitor poll vote and send the info to a PHP script that saves it into the MySQL database • Display poll results before and after visitors answer the question(s) i.e. if no one has answered the poll yet, flash should say so, then once at least one person has answered Flash updates the message to say there has been one participant etc. and show the current poll results.

  11. Example: Rate/Vote • Flash MySql Rating/Voting • Have visitors rate images, songs or videos used in project • On frame/In Movie that displays media, have a button that records the visitor vote and send the info to a PHP script that saves it into the MySQL database • Display rating results before and after visitor vote i.e. if no one has rated the image, it (Flash) should say so then once at least one person has voted, update the message to say there has been one vote, etc. and show the current vote results.

  12. Example: Guestbook/Comments • Flash MySQLGuestbook/Comments • Have visitors enter comments about project into input fields in Flash, send info to PHP • PHP script saves comments into the MySQLdatabase, returns success or failure to save comment to Flash • Display comments before and after visitor comment i.e. if no one has commented, it (Flash) should say so then once at least one person has commented, update the message to say there has been one comment or just show the comment in a list of comments immediately, etc.

  13. Example: Login • Flash MySQL Login • User login system: have visitors login info into input fields in Flash, send info to PHP • PHP script checks login info against what is saved in the MySQL database, returns success or failure to login to Flash

  14. Example: Use Imagination • Use your imagination to think of other ways to interact • Possible to satisfy two requirements of the project in one: • If you had an image gallery or mp3 player as part of your project, instead of storing media data in a text/XML file, store the data in MySQL • Use PHP to create text/XML file with the location of the media, title, caption, author etc. -> Flash uses this file to load media data. • Flash displays media with rating buttons/input fields, send rating data back to MySQL via PHP • *Could also create a backend in Flash that allows the Flash site administrator to edit/update the media info – file location, title, author etc. – stored in the MySQL database from Flash (via PHP) • PHP updates the text/XML file when database is changed.

  15. Tip for Success • At this point in the course you are familiar with importing external text and XML • If using PHP to output text/XML, you process that output the same way you would an XML/text file not produced by PHP • (you would probably tell Flash to open the text/XML file created by PHP, not the PHP script) • If using PHP to pass variables i.e. in Flash vars format, then Flash would request the PHP file directly • *** Whatever the Scenario: Make sure your PHP code works.***

More Related