Loading images dynamically in flash MX movie
This tutorial loads images dynamically. It works with two flash movies
1. Movie1(snapshot01.swf) is the container.
2. Movie2(snapshot02.swf) is the object.
When a button is pressed, movie2 loads in a movieclip of movie1, then image loads in movieclip of movie2.
Movie1: (snapshot01.swf)
1. First draw a rectangle, select the rectangle..create a movieclip with name loadMovie & instance loadMovieMC. Make sure center of the movieclip should be left & top corner of the rectangle
2. Take a new layer and create 5 buttons (1, 2, ..5). Give instance names button1, button2,....button5.
3. Add a new layer on the top with empty key frame. In that frame add action as given below:
loadMovieMC.loadMovie("snapshot02.swf"); file://movie1 is load in loadMovieMC clip
_root.getImg="image01.jpg"; //url of image which will load in movieclip of snapshot02.swf
_root.getImgName="img 1 | internetCross images"; file://variable value is passed to snapshot02.swf
button01.onRelease=function(){ file://function execute when a button is pressed
loadMovieMC.loadMovie("snapshot02.swf"); file://snapshot02.swf is loaded in a movieclip
_root.getImg="image01.jpg";
_root.getImgName="img 1 | internetCross images";
}
button02.onRelease=function(){
loadMovieMC.loadMovie("snapshot02.swf");
_root.getImg="image02.jpg";
_root.getImgName="img 2 | internetCross images";
}
button03.onRelease=function(){
loadMovieMC.loadMovie("snapshot02.swf");
_root.getImg="image03.jpg";
_root.getImgName="img 3 | internetCross images";
}
button04.onRelease=function(){
loadMovieMC.loadMovie("snapshot02.swf");
_root.getImg="image04.jpg";
_root.getImgName="img 4 | internetCross images";
}
button05.onRelease=function(){
loadMovieMC.loadMovie("snapshot02.swf");
_root.getImg="image05.jpg";
_root.getImgName="img 5 | internetCross images";
}
Movie1: (snapshot02.swf)
1. Draw a small rectangle(width=2, height=10), make it a movieclip & give a instance name bar. This will act as progress bar when a image loads in to movie.i.e., preloader. Create a dynamic text field, give var name txt.
2. Add a new layer..with two key frames, in the 2nd frame add below script:
totBytes=getBytesTotal();
bytes=getBytesLoaded();
bar._width=bytes/1000;
txt=int((bytes/totBytes)*100)+'%';
if(getBytesLoaded()>= getBytesTotal()){
gotoAndPlay(3);
}else{
gotoAndPlay(1);
}
3. Now insert new Scene(imageloader). Create a movieclip, with instance img1. Images load in this movieclip with the help of value passed from movie1 when a button is pressed.
4. Make dynamic text field with var name imgName. This is used to get value from Movie1.
5. Add new layer & insert below script:
img1.loadMovie(_root.getImg); // of the image from movie1
imgName=_root.getImgName; // value from movie1