Archive for January, 2009|Monthly archive page

YAMLA – Beta Release Soon!

icons

In a couple of weeks , i hope so … I will have my new application up and running for beta …

I’am still very busy finetuning the application , while another force has joined my side , his prime mission will be developing the yamla website where users can registrate for Beta tester, submit bugs , submit ideas and folow the develop process of Yamla!

I’am still backhold about the whole concept … You’ll See for yourself in a couple of weeks  …

Upload Multiple Files in Flash CS3

In this little tutorial i will show you how we can upload one or more file(s) using the FileReferenceList in Flash CS3.

We will use amfphp to upload the image to a location on our server … if you do not have amfphp installed, check out my prevouis post …

We will begin by declaring a new FileReferenceList object … after that we will set the object to show the browse window to select the files that need to be uploaded.

We also need to listen for the select event , this event is triggerd whenever enter is pressed, or the select button is clicked from the upload component.

Creating a new FileReferenceList

Creating a new FileReferenceList

Now we specify the upload destination location, hereby i use a php file that uploads the file from the uploadReferenceList to the location specified in the php file (a directory on our amfphp server).

Upload Script PHP

Upload Script PHP

Now having than that, we now specify the location of this file in Flash.

Upload Script Location

Upload Script Location

Now , this is what the fileSelectHandler looks like, we will loop through the fileList of the FileReference (so all the files we selected for upload), and push them into a custom function uploadSingleFile….

Select Handler

Select Handler

Here we just upload the file that was passed into the function to the php file on our amfphp server …

We also add a complete handler , so can trigger an action for the upload complete event.

Upload Single File

Upload Single File

Upload Complete Handler

Upload Complete Handler

Flash Remoting for PHP – Part 2 – Creating my own Service in amfphp (getting data)

After we got the installation working of amfphp we are now going one step further …if you missed it, find it here!


What will we need?

- correct installation of the amfphp service (0n webservice or locally)

- a php editor (personal using Adobe Dreamweaver)

- if using a amfphp installation on a online webserver, a ftp program (using FileZilla)

What is a amfphp service?

Well an amfphp service, is actually a php class that contains one or more function that handle the retrieval of database data

Example files

For a good understanding and following of this tutorial i created folowing database: designz_labs_amfphp with one table: books

Database and Table structure

Database and Table structure

for this tutorial I recommend using a local verison of amfphp using Mamp (Mac) of Wamp (Windows).

You can download the database file here , so you can follow along with the same information.

Creating the BookService

Now we will create a service that will retrieve all the books in the tabel books

Different steps:

- importing the database and creating a new database user with the right right

- opening the php editor and creating a new php file

- creating a new class BookService

- creating a basic constructor holding the connection details

- creating a new function (method) : getBooks

- calling the php function inside flash using amfPHP

Importing and User creation

importing : on the phpMyAdmin main page you will be able to import a database, do this and according to the .zip file download from above link.

user creation: on the same main page , go to Rights or Privileges and create a new user (user: books , password: books , Host:localhost) and make sure that the user has select and insert rights. This account information will be needed to have the tight privileges on the database table.

Creating a new class: BookService

open up a php editor and create a new php file.

Now create a new class: BookService

Creating the BookService

Creating the BookService

Creating the basic constructor with database connection data

Now we will add a basic constructor, where we will set connection data (telling the php that we are connection to localhost, with user: books having the password: books) and select database: designz_labs_amfphp for connection.

Creating the Basic Constructor

Creating the Basic Constructor

Creating a new function getBooks

In this peace of php we will add a new function “getBooks” , we select every record in the table “books” , and add all these records to an array … after completion the array will be returned to the amfphp , which will be called in Flash.

Finally save this php file into the amfphp service directory… Now we are ready to call this function from flash and process the results!

getBooks Service

getBooks Service

Calling the getBooks function from Flash Actionscript

Calling the getBooks functions

Calling the getBooks function

We just make a new netconnection and a new responder (that will cary the answer = the database result data) with the answer function when completed.

Via the netconnection we connect to the url of our amfphp (this can be local or on the network), than we call the php file BookService and the function getBooks in that php file … giving it the responder as paramater.

When the function is called with result , the getBooksResult will be called , here we loop through each object in the result array, in this case all the titles of the books ….

Download the source fla here…!

Enjoy … the next tutorial on amfphp will be calling database action combined with custom parameters !