I have this array that contains the names of various images I want to load into Flash
var imageArray:Array=["image1","image2","image3","image4","image5","image 6","image7",
"image8","image9","image10"];
Now I want to create 10 different buttons with each button loading in an image. I know there's a way to do this with a for loop without having to make 10 different buttons and writing 10 different functions. Not sure how to correlate the members imageArray with the generated btns.
i.e. btn1 loads in image1, btn2 loads in image2, etc.
var imageArray:Array=["image1","image2","image3","image4","image5","image 6","image7 ",
"image8","image9","image10"];for(var i:uint=0;i<imageArray.length;i++){
var btn:YourButton=new YourButton();
btn.ivar=i;
addChild(btn);
btn.x=..
btn.y=..
btn.addEventListener(MouseEvent.CLICK,clickF);
}
var ldr:Loader=new Loader();
addChild(ldr);
function clickF(e:MouseEvent){
ldr.load(new URLRequest(imageArray[e.currentTarget.ivar]));
}
Hi kglad.
I am wondering if you can help me on the same subject:
i used your above code as such, (below,) and it loads the first image in the array, while what i'd like is to add code that loads the elements of the array - the sequentially numbered images, one right after the other to create a moving image effect, that when u click the btn you get the pics loading 1,2,3,4,5 etc.. with a tiny delay in between so it looks like silent movie. Plz consider that i am not an event intermediate and need examples of code, if you do decide to help out. thnks for your time.
import flash.net.URLRequest;
import flash.display.Loader;
var imageArray:Array=["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg","7. jpg",
"8.jpg","9.jpg","9.jpg"];
for(var i:uint=0;i<imageArray.length;i++){
var btn:YourButton=new YourButton();
btn.ivar=i;
addChild(btn);
btn.x=0;
btn.y=0;
btn.addEventListener(MouseEvent.CLICK,clickF);
}
var ldr:Loader=new Loader();
addChild(ldr);
function clickF(e:MouseEvent){
ldr.load(new URLRequest("D:/flash cs5.5/image_sequence/twirlSeq/"+imageArray[e.currentTarget.ivar]));
}
North America
Europe, Middle East and Africa
Asia Pacific