Tutorial details: Introduction to Flash and PHP
Difficulty Level: Intermediate
Requirements: Flash MX, PHP, Apache
Assumed Knowledge: Familiarity with basic actionscript (v1)
File(s) to Download: nwjv.zip
Online Example: None
Introduction to Flash and PHP
This is the first part of a series of tutorials looking at using PHP and Flash. In this first tutorial we're
going to take things relatively easy. Over the course of the next few pages we are going to learn how to send
data from Flash to PHP and back again. The basic overview is this:
Flash sends a number to the PHP script -> PHP script multiplies number by 7 and returns it to Flash -> Flash displays new number
Easy eh? Actually as you'll see it really isn't that hard, and don't worry if you've never seen a PHP script before, there's nothing complicated about the one
we'll use. I can already hear some people shouting "Sure, but Flash could do this multiplication on it's own!!" - and right you are, but then that
wouldn't be much of a PHP tutorial would it.
Installing PHP on your computer is the big task, and way beyond the scope of this tutorial,
but never fear, there are several options available to you:
- If you already pay for web hosting then make enquiries with your hosting company.
They do all the set-up for you. Ideally you want to be running PHP, Apache (web server) and mySQL (database) so enquire with
your host about any such packages they do. The main downside of this approach is that in order to test anything you have to
upload it to the remote server, and of course your hosting fee will increase. The upside is that everything you do
will be available to the 'outside world'. NOTE: you could install everything on your own machine and open that up to the outside world,
but unless you happen to be very knowlegable about server side stuff then that idea is quite frankly crazy-talk!!
- Use a preconfigured package like the excellent one at
www.firepages.com.au -
this makes installing PHP, Apache and mySQL on your own computer easy. You may need to read up more about
installation in order to make certain tweaks to the setup, but for many this is the easiest option. The main upside is that you can test everything quickly
and easily on your own machine. The main downside is that your work can't be seen by others via the web (well ...see above!)
- Install PHP, mySQL and Apache yourself from scratch. Use one of the many tutorials found via a
search engine like Google, or from some of the excellent PHP-specific forums such as
www.phpfreaks.com to guide you through the setup. The main up and downsides to this are as above.
This tutorial assumes that you have PHP and Apache running either locally or on a remote server. Everything from this point onwards
is written with that assumption - no, no don't cry! If you have problems with the installation don't give up - insalling PHP may seem a
little daunting, but take advantage of those PHP forums and all the lovely kind forum members just hanging around waiting to help you ;)
Do bear in mind that it is highly likely your question has been answered before, so use the forum's search facility first before posting.
Throughout this tutorial I will refer to "generating" files. If you are using a remote server this
assumes that you remember to upload them to the correct directory on that server before testing.
If you are running a local server it assumes you have your site structure (see below) set up in your Apache htdocs folder.
1. Before going any further we are going to set up a basic folder structure so we can keep our files organised.
Mirror this structure on your remote server if you are using one and if you are running PHP and Apache locally then create
this structure in your Apache/htdocs folder:
I called my main folder nwjv (a combination of my initials and that of Justin Vincent, a mighty PHP-weilding friend of mine).
It may be best to stick with this name for now.
2. Next we're going to create a fla and set up the export options as we want them to be.
So, open a fla, name it dogYears.fla and save it in the flash folder you just created.
Now, within the flash file go to file -> publish settings and click on the first tab: formats.
Make sure the flash and html boxes are ticked, then click on the folder to the right of the flash box.
A popup window appears and you should navigate to the swf folder you just created, as we want to save our swf
as dogYears.swf in that swf folder.
Now repeat the above process for html. All our html files are going to go directly in to the nwjv folder -
I haven't created a specific folder for html.
3. Publish the movie (file -> publish) and check that the swf and html end up in the correct folders. They did? Excellent!
|