Need ARRAY help in Flash.
- Started
- Last post
- 5 Responses
- Bureau
Ok Im trying to do something that seems simple to me but I could be wrong. I want to load a new SWF everytime you click on a button based on the array. I can get it to load the first movie in the array but I cant figure out how to get it to cycle through the entire array in order. Here is my code.
I have this in the first frame.
movies = new Array("mc1.swf","mc2.swf","mc3.s...
i=0;then I have this in my button.
on (press) {
loadMovie(movies[i],_root.loadWi...
}what am I missing? Thanks.
- Solid0
You need to increment your 'i' variable each time you call loadMovie();
------
on (press) {
loadMovie(movies[this._parent.i... , _root.loadWindow);
}
- Bureau0
Thanks! That worked! I changed the button script to this.
on (press) {
loadMovie(movies[i],_root.loadWi...
i++;
}But now I have another problem. When it reaches the last array how do I make it loop back to the beginning?
Do I need to do an IF statement saying that when it reaches the last array to set i back to 0?
- Bureau0
I think I got it. For anyone that cares I modified the button script to this.
on (press) {
if(i==3){
i=0;
loadMovie(movies[i],_root.loadWi...
i++;
}
else{
loadMovie(movies[i],_root.loadWi...
i++;
}
}
- Solid0
You've got the right idea, but what happens if you add more movies? The movies array length may not always = 3 ..
check this out:
http://pastebin.coconut.se/?id=4…
- Bureau0
If I change the length then all I have to do is change one number. Not a big deal.