Download FLA | example


Ok, the aim of this tutorial is to provide a simple way to add a background (and/or a screensaver) to your website with text field showing how many bites are loaded. In this tutorial we will start first with the background. Then we will see the screensaver.

Assuming that "MainFolder" is the folder where you will put the final swf.

Create in "MainFolder" a new folder named "background". This is the folder where the background image files and one php file will be.
Create in "MainFolder" a new folder named "screensaver". This is the folder where the screensaver image files and one php file will be.
Create in "MainFolder" a new folder named "inc". This is the folder where you will put the file (and all the other include file you can use for your future website).

So you should have something like this:
  • background
  • inc
  • screensaver

First, as all developers I suppose, we will create inside the MainFolder a "" file. This file is here to help development. In fact, all our php files will call this one to get the WEBSITE's PATH.
Here is the file:


//folder for include file

$C_INC = $C_ROOT."inc/";

//folder for background file

$C_BG = $C_ROOT."background/";

//folder for screensaver file

$C_SS = $C_ROOT."screensaver/";


The $C_ROOT var will be sent by php file including the, it refers to the MainFolder folder. We will see this later on the tutorial.

Now create a new "" php file inside the "inc" folder. This file will have all the constants needed (for our tutorial and for your future website).
Here is the file:


//all the valid extension for the background

$C_MYEXTENSION = array ( 'jpg', 'jpeg', 'png', 'gif', 'swf' );

//all the valid extensions for the screensaver

$C_MYEXTENSIONSS = array ( 'swf' );


In this file we are creating two arrays. The first one is holding all the extension for the background file, the second for the screensaver. I hope it's enough clear. I could put all in one file, but I think it is better this way: one php file for path, another one for constants used.

c. listfile.php
Ok, now we need to make a php file that will check inside a folder all the file, then keep only the file with the extension we want (those which are define in ""). The php file will finally echo the name of the file to the flash movie.
We will save the file in the folder "background" with the name "listfile.php".


//give the relative path of the root (MainFolder) of the

$C_ROOT = "../";

//get the then know all the relative path from the root.

include_once $C_ROOT."";

//include all the constant like our array of extension

include_once $C_INC."";

//opening the current folder


//make an empty array that will get our background
//filename of the actual folder

$ourFile = array();

// while next file in the folder exist

while ($file = readdir($handle)) {
// don't check ./ and ../
if ( ($file != ".") && ($file != "..")) {
// split the string in an array, substring
// separate by a '.'

$ext = explode('.', $file);
// how many value in the array
$howmany = count(ext);
// redefine the var ext. Get the extension ie the
// last substring
$ext = strtolower($ext[$howmany]);

// check the extension of the file. If the
// extension is on our array ( file)

// then add the filename to our array of
// background
 if( in_array ($ext, $C_MYEXTENSION) ) array_push($ourFile, $file);


// selecting one of the value of the ourFile array, means
// that we are taking one of the background file name

$theFile = $ourFile[array_rand($ourFile)];

//deleting the handler


//send it to flash

echo "&thefile=".$theFile."&";


Ok, so now we have a php file that echo a filename, like eg:

This file is inside the folder "background", so you need to put some background image files inside the "background" folder.

Then test the file by opening your browser like:

You should have something like:

For the screensaver it's the same thing.
Just copy this file, and some image files inside the "screensaver" folder.

Ok so all the php side is done :)

Let's go in Flash now !!! (I was impatient too)