Search Flex Components Free

Custom Search

December 10, 2007

Building an online store using Flash and AMFPHP

Intro

Since Flash is gaining more and more acceptance as a web interface to many sites and applications in Internet, things comes easier to developers trying to do interfaces totally flash-based. With the release of Flash MX, a renewed and clearest OOP language is availed as an invaluable tool, since ActionScript becomes a more stable and full-featured language. On the fly Movie Clips and Text fields creating, callbacks for buttons, better support for XML and server side tools like Flash remoting appears to move Flash to a new generation of web based applications. Macromedia propose a name, RIA (Rich Internet Applications) and shows his own site as an example. There were a lot of discussions about the topic, but despite disagrees, the effort in doing things more easy and attractive to users is the background point.

Through this tutorial, we try to build a simply online store, showing how Flash can manage the common steps of an e-commerce site. A database will be used and in the server-side, we will use Flash Remoting. Traditionally, Flash Remoting is a native ColdFusion feature, availed as an extend to .Net and Java trough J2EE Application Servers. Flash Remoting allows Flash movies to call remote server side applications, passing parameters and receiving requests, without need of knowing nothing about the server side implementation, but about which info to pass and which info who will receive. This calls are usually named Remote Procedural Calls (RPCs), and transfer serialized, type-persistent objects directly between the server and a Flash MX client. Developers on both sides could agree in the needs and ways of calling methods in order to build a system. Also, trough AMF (Action Message Format) , the exchange of information's is not only faster, but could pass objects (and not only name/value pairs) between Flash and the server in binary format. This allows to easy develop complex applications that rely on an efficient way of send/receive data.

But recently, one of the Forum Administrators here in Flash-db (Musicman) exposed the binary format of the AMF packet, open the door for an implementation of the AMFPHP Project, where a few developers has building an open source project to port Flash Remoting to PHP. This project allow Flash developers to use Flash remoting in a PHP environment, and with (almost) the same's functionality than in the CFM servers. For this tutorial, we will use the 0.5.1 version, but probably we need to update this part since the project is running and growing up. Anyway, using Flash remoting we can manage the database interaction in one simple class. Those who has worked with databases and Flash could take advantage of the clean way of handling RPC, both in server and Flash side.
Building an online store using Flash and AMFPHP

Intro

Since Flash is gaining more and more acceptance as a web interface to many sites and applications in Internet, things comes easier to developers trying to do interfaces totally flash-based. With the release of Flash MX, a renewed and clearest OOP language is availed as an invaluable tool, since ActionScript becomes a more stable and full-featured language. On the fly Movie Clips and Text fields creating, callbacks for buttons, better support for XML and server side tools like Flash remoting appears to move Flash to a new generation of web based applications. Macromedia propose a name, RIA (Rich Internet Applications) and shows his own site as an example. There were a lot of discussions about the topic, but despite disagrees, the effort in doing things more easy and attractive to users is the background point.

Through this tutorial, we try to build a simply online store, showing how Flash can manage the common steps of an e-commerce site. A database will be used and in the server-side, we will use Flash Remoting. Traditionally, Flash Remoting is a native ColdFusion feature, availed as an extend to .Net and Java trough J2EE Application Servers. Flash Remoting allows Flash movies to call remote server side applications, passing parameters and receiving requests, without need of knowing nothing about the server side implementation, but about which info to pass and which info who will receive. This calls are usually named Remote Procedural Calls (RPCs), and transfer serialized, type-persistent objects directly between the server and a Flash MX client. Developers on both sides could agree in the needs and ways of calling methods in order to build a system. Also, trough AMF (Action Message Format) , the exchange of information's is not only faster, but could pass objects (and not only name/value pairs) between Flash and the server in binary format. This allows to easy develop complex applications that rely on an efficient way of send/receive data.

But recently, one of the Forum Administrators here in Flash-db (Musicman) exposed the binary format of the AMF packet, open the door for an implementation of the AMFPHP Project, where a few developers has building an open source project to port Flash Remoting to PHP. This project allow Flash developers to use Flash remoting in a PHP environment, and with (almost) the same's functionality than in the CFM servers. For this tutorial, we will use the 0.5.1 version, but probably we need to update this part since the project is running and growing up. Anyway, using Flash remoting we can manage the database interaction in one simple class. Those who has worked with databases and Flash could take advantage of the clean way of handling RPC, both in server and Flash side.



Amfphp home page at Sourceforge




The Flash implementation use a couple of mayor class to manage the interface and the shopping car, and a step by step checkout process in a more procedural way. This is not a fully OOP application, perhaps because the author of this lines is not so average in this way of scripting, but also because this little application has modest needs, and takes his own way as a real implementation.

Installing demo files

If you don't have a local server installed with PHP support, or a database, continue reading, we will give you some hints (page 6) on how to install both. You need first download and install the AMFPHP library . If you want some help in doing this, read this tutorial first. Then download the files for our online store here. Here's a quick setup:

1. Unzip all the files to some folder under your root web folder
2. Open inc_sql.php and change Database, Host, Username and Password to match your needs
3. Run setup.php to create Database and tables (or use shopping.sql trough phpMyAdmin)
4. Open gateway.php and modify the path to the flashservices/app/Gateway.php from the amfphp packet
5. Open shopping.fla and change "pathToRemoting" variable in the first frame of the code layer (line 2) to match your path
6. Publish the movie

Ok, lets take a more closer look.

Related Flex Tutorials