Help! Clever person needed. Button/Dynamic text problem

I can’t get code in my button to change the values displayed in my dynamic text boxes.

I have a column of twelve dynamic text boxes which display numbers stored in an array. The array contains more than twelve numbers. I want to use buttons to refresh the information in the boxes (effectively creating a scrolling effect) so that the remaining contents of the array can be revealed as required. In the code below Stats1 etc. refer to the dynamic text. The array is called Stats4display. This shows the information fine.

Stat1=Stats4display[x];
Stat2=Stats4display[(x+1)];
Stat3=Stats4display[(x+2)];
Stat4=Stats4display[(x+3)];
Stat5=Stats4display[(x+4)];
Stat6=Stats4display[(x+5)];
Stat7=Stats4display[(x+6)];
Stat8=Stats4display[(x+7)];
Stat9=Stats4display[(x+8)];
Stat10=Stats4display[(x+9)];
Stat11=Stats4display[(x+10)];
Stat12=Stats4display[(x+11)];
Stat13=Stats4display[(x+12)];

The button (in the same timeline on a different layer) has this code:
on (release) {
x++;
}

I had hoped that by incrementing the value of x I could update all the dynamic text boxes with the next value along in the array. Why doesn’t this work? Some kind of scoping problem? Or is there an easier way to do this?

Any help would be much appreciated.

First of all, this loop is equivalent to your group of 13 assignments:


for (var i = 0; i <13; ++i)
{
  eval("Stat"+(i+1)) = Stats4display[x+i];
}

Secondly, incrementing x will only have an effect if after you increment x, you re-execute the code that does the assignments. Once the assignments are performed, they don’t get automatically adjusted when you increment x.

Like so:


on (release) {
  x++;
  for (var i = 0; i <13; ++i)
  {
    eval("Stat"+(i+1)) = Stats4display[x+i];
  }
}

Something like this?

function refreshValues(x) {
	for (var i = 1; i<=13; ++i) {
		this["Stat"+i] = Stats4display[x+i-1];
	}
}
refreshValues(0);
on (release) {
	refreshValues(++x);
}

To Jbum,

Thanks a lot for your suggestions.

When I tried what you suggested I got an error message (Left side of assignment operator must be variable or property.)

Why would that be then?

Thanks Claudio,

Where would that code go? In the button or on the main timeline? Sorry I’m a complete newbie. Duh!

On the main timeline:

function refreshValues(x) {
for (var i = 1; i<=13; ++i) {
this["Stat"+i] = Stats4display[x+i-1];
}
}
refreshValues(0);

On the button:

on (release) {
refreshValues(++x);
}

In claudio’s example, everything up to the ‘on (release)’ would likely go in a frame script.

The stuff after and including on(release) should be attached to the button.

Whoops - I see I cross-posted with Claudio. :slight_smile: