surabaya web designer
cheap web promotion indonesia
design graphics and online shopping cart
     category      articles    






CSS Style


Design Graphics

Flash Animation

Internet Radio




Search Engine


Security Web




Software Web

Load Images In Flash From PHP

This knowledges was getting from
First, you have to download this file to make you quick to learn

Open the Actions Panel F9 and we will begin going through the code used in this example. You will first see a block of code and then it will be explained.
function loadImage(id:Number) {
var resultLv:LoadVars = new LoadVars();
var sendLv:LoadVars = new LoadVars();
resultLv.onLoad = function(success) {
if(success) mcLoader.loadClip(imagePath + this.image, loadContainer);
sendLv.sendAndLoad(phpPath + "?id=" + String(id), resultLv);

This function will load in image, taking an id as an argument. We need to setup 2 loadVars objects. One to load the PHP and another to trap the result from the PHP. Next we have an onLoad function that is called when the PHP file is successfully loaded (this example does not account for errors). Inside this function is where you will find our loadClip() method which we will explain a little later on. Finally we have our sendAndLoad which calls the PHP, passes in the path and the object to store the response.
var loadButtons:Array = new Array('loadBtn1','loadBtn2','loadBtn3','loadBtn4','loadBtn5','loadBtn6');
var loadContainer:MovieClip = this.createEmptyMovieClip("loadContainer", this.getNextHighestDepth());
var siteUrl:String = "";
var imagePath:String = siteUrl + "path/to/images/";
var phpPath:String = siteUrl + "path/to/loadImages.php";

Most of that is straightforward. We have our array of buttons that we dragged to the stage. An empty movieclip where our loaded image will end up. Then we have 3 variables containing the site path, image path and php path.
var mcLoader:MovieClipLoader = new MovieClipLoader();
var mcLoadObj:Object = new Object();
mcLoadObj.onLoadInit = loadInit;
loadContainer._x = loadContainer._y = 10;

Next we initialize a new MovieClipLoader and assign our listeners, so let's get started. mcLoadObj is an object that we attach our listener methods to. onLoadInit is called once the image is loaded and visible. addListener accepts one argument which is the object we used to attach our methods to. Finally for visual purposes we nudge the empty clip 10 pixels on both the X and Y axis.
function loadInit(target:MovieClip) {
trace("File Loaded");

A simple function that you can use to preform tasks now that the image is loaded.
function assignButtons() {
for(var i in loadButtons) {
this[loadButtons[i]].numberTxt.text = String(Number(i) + 1);
this[loadButtons[i]].onRollOver = function() {
this[loadButtons[i]].onRollOut = function() {
this[loadButtons[i]].onRelease = function() {
loadImage(Number(String(this).substring(String(this).length - 1))-1);

This function is semi-advanced and is only used to simplify the proces of assigning rollover, rollout and click events to our buttons. Basically it is an open-ended loop that runs through the loadButtons array and assigns our events as described a second ago. The loadImage function is called within the onRelease function to start the process of loading an image.

The last step on the Flash side is the magic line that calls the button assignment function.

Next up, PHP Code
Now that we have the Flash portion squared away let's move onto the PHP code.
$imageId = $_GET['id'];
$images = Array('img1.jpg','img2.jpg','img3.jpg','img4.jpg','img5.jpg','img6.jpg');
if(is_numeric($imageId)) {
print "image=" . $images[$imageId];

This part is simple in the example, but you really should add a lot more security for a live application. We first grab the id from the url using the super variable $_GET. Then we assign a list of images that will match an id. The last step is to send back the image name to Flash from our image array by referencing the id we passed in.

That is basically it for this tutorial. You should now have a fully working image loader that is getting the image name from a PHP file.

Here is a live example use for loading images that I created. It takes this tutorial to a completely new level with dynamic reflections, multiple images and all input for the user to load in their own image.


Load variable from PHP to Flash

Flash Animation

Secure SWF Files

Flash animation

Pass value to HTML or PHP