TinMonkey,
All you need, as far as I can tell, is your array. I don't see any
value in creating additional variables that point to array indexes, since
you can always simply reference those indexes directly.
[quoted text, click to view] > I need to set up a script so that when i press a
> button it changes the path of a loader component
> i have on stage called pic2 to the next element in
> the array and loads it.
Let's step through what you have so far.
// Change image function
function nextImage1(number) {
if(number >= 0 && number < images.length) {
currentImage1 = number;
_root.viewer.contentHolder.pic1LoadBar._visible=true;
pic1Content = images[number][0];
pic1.load();
}
}
You'd call this function with a parameter of some kind. Let's say ...
myButton.onRelease = function() {
nextImage(5);
}
So nextImage() will be called. First thing it will do is is check if
its parameter, number (in this case, 5), is greater than or equal to zero
(yes) and less than the length of the images array (yes; images holds ten
items). Because this condition evaluates to true, it proceeds to set a
variable currentImage1 to number; that is, to set currentImage1 to 5. But
why? Where is this variable used?
Next, a nested movie clip is set to be visible (pict1LoadBar, which
resides within contentHolder, which resides within viewier, which resides in
the _root). Is this your loader component? If so, is this the Loader UI
component that ships with Flash? If so, you can look up the Loader class in
the ActionScript dictionary to see all the methods and properties available
to you for this class.
I see Loader.contentPath as a property, which specifies the path to the
external JPG or SWF. That means you can reference an instance of this
component and address its contentPath property. So assuming the instance
name of your Loader componet is pic2 (as you've said), you would reference
it like this:
pic2.contentPath = something ...
-- of course, the path to this component is up to you. If it sits in the
_root and your code is in the root, you don't need a path. Simply pic2 will
work. If your code is somewhere else but pic2 is in the _root, you might
write ...
_root.pic2contentPath = something ...
Okay, and you know what the image is, because it's based on the number
that was passed to this function (5). So your final function might look
something like this:
function nextImage1(number) {
if (number >= 0 && number < images.length) {
_root.pic2.contentPath = images[number - 1];
}
}
.... which essentially looks to the images array at the index provided.
Arrays start at zero, not one, so if you want to call the fifth image, you
need to specify index 4. (That's the number - 1 part.) And that's it.
pic2's contentPath property will be set to images[4], which is image5, as
specified earlier.
The only problem with your initial array is that you haven't supplied
strings as your array entries.
//create image array
var images:Array = new Array();
images[0] = image1;
images[1] = image2;
// etc.
Since image1 isn't in quotes, ActionScript is looking for a variable
named image1 that contains ... who knows what? No. What you want is for
images[0] to literally equal image1, so ...
var images:Array = new Array();
images[0] = "image1";
images[1] = "image2";
Make sense?
David
stiller (at) quip (dot) net
"Luck is the residue of good design."