3 Replies Latest reply on Aug 30, 2009 2:56 PM by kglad

# Array loop - assigning variables

Hi All,

This is similar to a question I previously had, (which kglad so kindly helped me with) so please bare with me.

Here is the code:

```nor = Array(a, b, c);
aVar = Array();
aVar[0] = 0;
aVar[1] = 0;
aVar[2] = 0;

for (i=0; i<nor.length; i++)
nor[i].onRelease = function() {
nor[i].ivar=i;
aVar[this.ivar] = 1;
trace(aVar[this.ivar]);  // this outputs "1" //
for (i=0; i<nor.length; i++)
trace(aVar[i]);  // this outputs "0, 0, 0" //
};
```

The problem is that when tracing the "aVar" array, one of them should be "1" (so I think)

Any Ideas?

Thank you

• ###### 1. Re: Array loop - assigning variables

ivar was undefined the way you were using it.  try:

````nor = Array(a, b, c);aVar = Array();aVar[0] = 0;aVar[1] = 0;aVar[2] = 0;for (i=0; i<nor.length; i++)``  nor[i].ivar=i;`
`nor[i].onRelease = function() {          aVar[this.ivar] = 1;        trace(aVar[this.ivar]);  // this outputs "1" //            for (i=0; i<nor.length; i++)                trace(aVar[i]);  // this outputs "0, 0, 0" //};````

• ###### 2. Re: Array loop - assigning variables

ahhhh... of course.

````nor = Array(a, b, c);aVar = Array();aVar[0] = 0;aVar[1] = 0;aVar[2] = 0;for (i=0; i<nor.length; i++)``  nor[i].ivar=i;`
`for (i=0; i<nor.length; i++)``nor[i].onRelease = function() {          aVar[this.ivar] = 1;        trace(aVar[this.ivar]);  // this outputs "1" //            for (i=0; i<nor.length; i++)                trace(aVar[i]);  // this outputs "0, 0, 0" //};````