Building the Back End of a Content Management System for Flash - Gluing it All Together
(Page 4 of 4 )
In a short summary of what we are hoping to accomplish, we enter the content we wish to display into our HTML form, and on submission, our PHP form processing script then takes that content and stores it in our text file database, where it keeps each variable name set to its content (content1_txt=content here). Then we have our ActionScript look for the database we told it to, and load the contents of that database into our dynamic text area in the Flash website.
Let's look at some of our ActionScript again in light of the information we just covered:
It is this line of ActionScript that ties it all together. This ActionScript code tells Flash where to get the information to get its data from. Once the entire movie loads, it also loads the external data from the data.txt file into the variable content1_txt and displays it in the movie.
Simplifying it a Bit
For simplicity, I want to combine my HTML form with my PHP script, since I know that I can embed HTML within a PHP script. So I place my HTML form in my backend.php script, and instead of pointing the form action to an outside PHP script, I can change it to refer back to itself, like this:
<form action="<?php echo $_SERVER['SCRIPT_NAME']?>" method="post" name="input" id="input"> |
Now, I have three steps.
The CMS in Action
In a quick review, you are entering text into a form, which is then processed via PHP, written to a data file, and then loaded into Flash through a dynamic variable. So far we have four different steps to our content management system. Let's see if we can reduce the number of steps we have.
Let's test it. Export your flash movie and upload it and your PHP script to your web server. It is not necessary to upload your data.txt file, as it will be created if it's not there; but since we want to see something other than a blank page let's upload it anyway. You can delete it later; just make sure you give it writeable permissions (777 will do fine). Point your browser to your flash_cms.swf file, and you should see what we entered into our text file earlier.
Now, I want to change the existing content from "This is the text that I want to display" to "This is NEW content!!!" So in a new browser window, I open my backend.php script, and enter my new content in the input text box, and submit it. If it is working correctly, you should see:
Your content has been saved.
This is what you submitted: content1_txt=This is NEW content!!!
Now, let's refresh our Flash movie, and VOILA! The new content is indeed there.

Now view the data.txt file stored on the server; this is what you will see:

In closing, this is not a glamorous software script by any means. However, it is an effective way to load external content into Flash without having to mess with the Flash or the data files themselves. Obviously, it would be just as easy for someone with the kind of knowledge to handle dynamic variables in Flash to adjust the text files, as we saw in the first article, and thus skip the most difficult step entirely. But for someone who doesn't wish to deal with FTP or database files, but would rather enter text into a form and have it just appear in Flash, this tutorial can help one accomplish just that.
Perhaps a part three to this tutorial would be in order, depending upon the sheer demand, dealing with multiple dynamic variables and forms, and implementing some formatting tricks. I will certainly be open to doing one as long as it would be something you as readers could use.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |