- Home
- Tutorials
- Flash
- Intermediate
- Flash photo Album.

photo Album
Amen KAMALELDINE
Amen is an industrial informatics engineer. he studied the first four years of his education in Faculty of Engineering in Lebanon. He went to France to Continue his studies by doing the fifth year of engineering and the master TIS (Technologie Information et Système) in the same time at UTC (Université de Technologie de Compiègne). He also work as a freelancer in flash development field. He is always interessted in the new multimedia technologies.
View all articles by Amen KAMALELDINEIn this tutorial you will learn how to create a flash photo album that loads external images, from a path that is specified in an external text file, we can use php language to make it more dynamic by making a script that will go through the folder and count the images, retrive their names and return the value to flash, so we don't need to update the text file if we added some new pictures; before you start you must have the knowledge of Action script language because you will notice that I just highlighted the important script lines.
here's what you are going to make
Ok first create a new folder name it "photo Album" open your flash software and let's start!
- Create two buttons name the next and previous; place them where ever you want on the stage of your movie, and name the layer buttons.
- Create a new layer name it "images".
- Draw a white rectangle with a line border that is hair line that will represent the shadow of the rectangle, although you can use the drop shadow that already exist in flash 8 effects, but this will produce more processor calculation.
- Convert you rectangle into a movie clip name it "imagebg", and give it the instance name "imgbg_mc".
- Once again convert the movie clip "imgbg_mc" into another movie clip name it "imageContainer" and give it the instance name "imageContainer_mc", center it on your stage or you can dynamically center it by script :this.imageContainer_mc._x=Stage.width/2;
this.imageContainer_mc._y=Stage.height/2;
- on a new layer call it script put this code://we use the LoadVars to load the external text file data that contains the images
//number and urls
var text_lv = new LoadVars();
text_lv.load("images.txt");
//refer the parent of the object in a property so we can access some function that
//the parent have and inaccessible by the text_lv object.
text_lv.parent = this;
//we use the MovieClipLoader so we can determine the width and height of the
//loaded image so we can perform our animation.
var img_mcl = new MovieClipLoader();
var handler = new Object();
var pos = 1;
handler.ref = imageContainer_mc.imgbg_mc;
//functions-----------------------
handler.onLoadInit = function(target_mc) {
//center the loaded image.
target_mc._x = -target_mc._width/2;
target_mc._y = -target_mc._height/2;
//initialize the _alpha to 0 so we can animate the fade in effect.
target_mc._alpha = 0;
//this function will be explained later.
tween(this.ref, mx.transitions.easing.Regular.easeOut, "_width", this.ref._width, target_mc._width+10, .5, true);
tween(this.ref, mx.transitions.easing.Regular.easeOut, "_height", this.ref._height, target_mc._height+10, .5, true, _root, "finish");
};
handler.onLoadComplete = function(target_mc) {
//do nothing.
trace("image loaded");
};
text_lv.onLoad = function(success) {
if (success) {
trace("text loaded");
this.parent.loadImage(text_lv["img1"]);
} else {
trace("loadin failed");
}
};
//this function is used to load an image in the imageContainer_mc.holder_mc
//clip
function loadImage(path:String) {
img_mcl.addListener(handler);
img_mcl.loadClip(path, this.imageContainer_mc.holder_mc);
}
- on a new layer name it btn_script place this code:next_btn.onRelease = function() {
this.enabled = false;
pos++;
//this code is to make a circular loading of the image so if the image count
//is greater than the max number given by text_lv["num"] we reinitialize //pos to the first image to load
if (pos>text_lv["num"]) {
pos = 1;
}
loadImage(text_lv["img"+pos]);
};
prev_btn.onRelease = function() {
this.enabled = false;
pos--;
if (pos<1) {
pos = text_lv["num"];
}
loadImage(text_lv["img"+pos]);
};
- Again on a new layer name it functions//now this function can be used for multiple type of animation for a movie clip //propreties like the alpha,width,height… and it can call a function at the end of //your animation.
function tween(_mc, easeType, type, begin, end, time, bool, mcf, functionToCall, param) {
myTween = new mx.transitions.Tween(_mc, type, easeType, begin, end, time, bool);
myTween.functionToCall = functionToCall;
myTween.param = param;
myTween.mcf = mcf;
myTween.onMotionFinished = function() {
this.mcf[functionToCall](this.param);
};
}
function finish() {
//her we call the fading effects for the image, after the background image
//has perform it’s animation.
_root.tween(_root.imageContainer_mc.holder_mc, mx.transitions.easing.Regular.easeOut, "_alpha", 0, 100, .5, true, _root, "enable");
}
function enable() {
prev_btn.enabled = next_btn.enabled=true;
}
9. the content of the images.txt is
num=3&img1=images/image1.jpg&img2=images/image2.jpg&img3=images/image3.jpg
Well I hope this tutorial helped you, and if you have any questions just go to the forums and ask.
Happy flashing.
Spread The Word
Attachments
14 Responses to "Flash photo Album." 
|
said this on 08 Feb 2007 9:02:39 AM CDT
Hi there, ive been through your tutorial and i have done everything you have said.just 1 question:what do you insert in the .txt file to call the images?
|
|
said this on 06 Mar 2007 6:45:42 AM CDT
I have the same question, where do the pictures come from?? I see the images.txt, but I see no reference to follow
|
|
said this on 17 Mar 2007 2:58:01 PM CDT
Hi, What Flash Version are you using? I can´t open it in Flash MX 2004
|
|
said this on 19 Mar 2007 2:24:13 PM CDT
Excellent, i was just wondering if there what adjustments would need to be made so that this application would automatically display new images placed in the images folder without having to ammend the .txt file first. thanks alot danny.
|
|
said this on 20 Mar 2007 3:04:47 PM CDT
Just a comment about your tutorial. The last line <script>img_mcl.loadClip(path, this.imageContainer_mc.holder_mc);</script> the reference you make to: Convert you rectangle into a movie clip name it "imagebg", and give it the instance name "imgbg_mc". This instance name needs to be : holder_mc.
Just having fun! :) Dave |
|
said this on 20 Mar 2007 4:18:58 PM CDT
In your instructions you neglected to mention holder_mc, why, what, where and when is this not mentioned. It's difficult to get it working has you designed it when the key part is missing in your instructions.
Now I've ranted - It still was a good tut. |
|
said this on 04 Apr 2007 9:27:30 AM CDT
Thanks for the tutorial! It helped a lot and I even created the php file like you suggested. Now I don't have to keep updating the text file anymore. I just changed the load part to -- text_lv.load("images.php"); -- and it's working like a charm.
|
|
said this on 01 May 2007 1:10:44 AM CDT
you forgot to mention anything about making the empty movie clip and nameing it "holder_mc" and where to put it. Thanks though, I did end up figuring it out.
|
|
said this on 22 Jul 2007 3:56:37 PM CDT
Great photo album! But I would not have been able to find the mistake. The downloadable file and the comments of others helped a lot.
I have not analysed the comments to actionscript code, but I think I will be able to understand part of this. |
|
said this on 10 Oct 2007 8:24:58 PM CDT
New to flash, but wanted to add index buttons to specifically call the images - as well as the prev and next buttons - any help on how to modify buttonscript to achive this would be great,
cheers nice little app. |
|
said this on 25 Oct 2007 12:06:45 PM CDT
Got a nice php add on for all you programmers out there. [script] text_lv.load("images.txt"); to text_lv.load("images.php")Create a file images.phppaste this into it images.php <?php //images.php this is a simple version to read out any file type placed in an image folder used in the tutorial $num=40; //totaal amount of pictures echo "num=$num"; //this starts of the string that was used in the tutorial $last = $num; //last is the string variable for the search or loop for($i = $last; $i > 0; $i--) { $img = 'images/img'.$i; //here the definition of the folder is made see how I added the prefix for the images if(file_exists($img.'.gif')) $img .= '.gif'; //filetype defined else $img .= '.jpg'; if(file_exists($img)) echo "&img$i=$img"; //this ends the string that was used in the tutorial } ?> [/script] Just having fun! :) Dave
|
|
said this on 07 Jan 2008 7:09:35 PM CDT
Hi. great tutorial. although took me about 2 hours to figure out the part you missed out about the holder needing to go inside the movie clip on another layer (yes i'm a complete noob at flash, only started learning it yesterday)
Any chance anyone could tell me how to get it working on a frame other than the first frame? |
|
said this on 25 Jan 2008 5:45:14 PM CDT
This one took me a long time to figure out:
To fix the images.txt file, take the part that says "images/" out all three times it appears. This should help ya'll out. |
|
said this on 06 Aug 2008 8:46:10 PM CDT
Hi,
This is a great tutorial but I have a few questions. 1. where do I set the path if I have the images in a image folder? 2. how do I set the path if want to put all actions and the movieclip inside a another movieclip instead of have it in the root scene?:o Please help :) Thank you, ren390 |



Author/Admin)