Global Variable?

Hey kirupians, really struggling with this - have got so far - think have cracked it and SLAM brick wall… groan

I have an array holding ‘image’ and ‘name’

name loops fine and populates a load of movie clips underneath each other…
i need for when this name is clicked to load an image in another movie clip (image name comes from the array)…

the code i have works but it only pulls throught the last item of the array which points to a problem with ‘i’ not being carried across the functions…?

that is the result of my investigation smokes pipe - any help would be appreciated!.


function loadceleb() {
 for (i=0; i<total; i++) {
  this.contentMain.attachMovie("chold", "hold"+i, i, {_x:xPos, _y:yPos});
  yPos += this.contentMain["hold"+i]._height+5;
  this.contentMain["hold"+i].text_hold = clname*;
 
// at this point textboxes are populated and set up on the stage

  imagename = image*;
 
// tried tying imagename to the image array so i can then use in the function below

  this.contentMain["hold"+i].onPress = function() {
   _root.image_cont.gotoAndPlay(109);
   this.celeb.img.loadMovie(imagename);
 
// this works fine but only pulls through the last image in the array - argh!

   trace(imagename);
   _root.image_cont.celeb.lineani.gotoAndPlay(1);
  };
 }
}
stop();

for some stupid reason I feel like helping you

search the forums! :stuck_out_tongue:

i have… and the site … and the net… hence the forum post -

ive tried defining ‘i’ before any function so its always there - no joy

have tried splitting the same then splitting it into two functions - still no joy…

its not like im not trying…:asleep:

this is the version that works perfectly expects only pulls the last image from the array


unction loadceleb() {
	for (i=0; i<total; i++) {
		this.contentMain.attachMovie("chold", "hold"+i, i, {_x:xPos, _y:yPos});
		yPos += this.contentMain["hold"+i]._height+5;
		this.contentMain["hold"+i].text_hold = clname*;
		imagename = image*;
		this.contentMain["hold"+i].onPress = function() {
			changeImage();
		};
	}
}
function changeImage() {
	_root.image_cont.gotoAndPlay(109);
	this.celeb.img.loadMovie(imagename, 1);
	trace(imagename);
	_root.image_cont.celeb.lineani.gotoAndPlay(1);
}
stop();

so you are saying you have an array of buttons, incremented with i

but they are only picking up the last array* element…


yerh, you’ve looked real hard for that one

only the image side of things, the buttons and text work perfectly - which makes me think its an error on my part on how im trying to get at the image array…

if i trace the whole array trace (image); it works fine…

t is loading the last image because the var imagename should be inside each movieclip.

when you say image name = 1 and the the cicle runs trhough, the image name will become the last one. and all btns are going to get that last name.

you should create vars inside the dynamic movieclips…

something like this:

function loadceleb() {
for (i=0; i<total; i++) {
[COLOR=“Red”]var BTN:MovieClip[/COLOR] = this.contentMain.attachMovie(“chold”, “hold”+i, i, {_x:xPos, _y:yPos});
yPos += this.contentMain[“hold”+i]._height+5;
this.contentMain[“hold”+i].text_hold = clname*;
[COLOR=“red”]BTN[/COLOR].imagename = image*;
[COLOR=“Red”]BTN[/COLOR].onPress = function() {
changeImage([COLOR=“red”]this.imagename[/COLOR]);
};
}
}
changeImage = function ([COLOR=“red”]Link[/COLOR]) {
_root.image_cont.gotoAndPlay(109);
this.celeb.img.loadMovie([COLOR=“red”]Link[/COLOR], 1);
trace([COLOR=“red”]Link[/COLOR]);
_root.image_cont.celeb.lineani.gotoAndPlay(1);
}

hope this helps…
any question…just post it

cheers

he’ll be back soon enough :stuck_out_tongue:

then again I don’t get your example loll

no its ok, i sorted it…

it was _global.i i needed to declare above my functions then use this throughout as opposed to just ‘i’ that way it holds the value of ‘i’ throughout the functions and picks the right image from the array when clicking on the button…

oh im good wiggles