4. Loading data from databases using name/value pairs (php example)
When using databases, there are SO considerations that you need to take in account. Not all databases are available for different platforms and some of them are difficult to manage for non-technical users. So we will show a common example second using PHP and MySQL. We don't give details about how to setup the environment, but you can read this note about installing Apache, PHP and MySQL. The Flash-back-end talk is very similar to the txt technique, that's the back-end language query the database and output name/value pairs that Flash reads. So steps are:
1. Setup database table(s)
2. Connect back-end language with database, query database and output as name/value
pairs
3. Read name/value pairs in Flash
Examples differs in back-end side, but Flash side is the same. Our table need to hold a table with 4 columns:
a. Id, usually an autonumber as unique identifier of a row
b. Title, text
c. Comments, text
d. Image, text
MySQL and PHP setup
This is a common setup in LAMP environments (Linux-Apache-Mysql-PHP) As exposed,
we expect that you have MySQL and PHP installed and running. There
are several packages that install all the necessary stuff (usually Apache-MySQL-PHP
and phpMyAdmin) automatically for you. Follow this for more detail directives. This example could work in any platform.
There are a lot of differences between Aces and MySQL, but let's emphasize this:
mysql doesn't have a visual standard client for managing it. You can use a command
line client, but as a Flash developer, is possible that you use a Windows or
Mac environments. There are several platform-related visual clients for MySQL
managing, but I prefer a popular multi platform manager: phpMyAdmin. This is
a Web based client usually used also by hosting providers, so using it allows
you to work in the same way in your local machine and in the production server.
You can download phpMyAdmin from phpmyadmin.net,
but if you have used some automatic package for installing Apache-PHP and MySQL,
is possible that is already installed. Look into your server root folder if
you have the phpMyAdmin folder, try to open in your browser. To modify user/pass
for Aces your DB, modify config.inc.php.
To setup the database, first create it using the "Create" database button. You can manually create table and add data using phpMyAdmin interface in a friendly way. But we will use a "shortcut", creating the table and inserting data in just one step using SQL. Here's the SQL script:
CREATE TABLE titles (
ID int(11) NOT NULL auto_increment,
Title varchar(255) NOT NULL,
Comments mediumtext NOT NULL,
Image varchar(255) NOT NULL,
PRIMARY KEY (ID)
);
INSERT INTO titles VALUES ( '1', 'Anastasio', 'This is a nice guy', 'an1.jpg');
INSERT INTO titles VALUES ( '2', 'In the car', 'Here's Anastasio's car', 'an2.jpg');


Trough phpMyAdmin, copy&paste this script into the SQL window (or use anastasio.sql file). You will create the table and insert data in it in one single step. Now we can move to the PHP script
----------------------------------------------------------------------------------------------------------------------------------------
TIP
A common technique for debugging the back-end script is to open it directly
into the browser to see if the output is as expected. So open the file trough
your server, something like: http://localhost/anastasio.php (modify to match
your own path) and see that the output is as the one previous exposed. Remember
to always do this prior to test your Flash movie: unexpected errors could break
your output!
----------------------------------------------------------------------------------------------------------------------------------------

5 most recent
Flash button as Flex icon
Tree menu
Flash Spell Checker
Flash Remoting Library
MX 2004 Chart/Poll
Articles