all groups > flash actionscript > january 2007 >
You're in the

flash actionscript

group:

Array in an Array


Re: Array in an Array DMennenoh **AdobeCommunityExpert**
1/7/2007 9:36:50 AM
flash actionscript:
Once your loop is complete, i is no longer a variable and aBilder[i] doesn't
exist. You need to store a reference to i within the clip, so that the clip
knows its index in the array:

for(var i:Number = 0; i < 7; i++){
aKnappar[i].myIndex = i;
aKnappar[i].onRelease = function():Void {
aBilder[this.myIndex]._visible = true;
}
}


--
Dave -
Head Developer
www.blurredistinction.com
Adobe Community Expert
http://www.adobe.com/communities/experts/

Array in an Array amilton22
1/7/2007 2:55:06 PM
var aBilder:Array = new Array(m1l, m2l, m3l, m4l, m5l, m6l, m7l);
var aKnappar:Array = new Array(k1l, k2l, k3l, k4l, k5l, k6l, k7l);

for(var i:Number = 0; i < 7; i++){
aBilder[i]._visible = false;
}

for(var i:Number = 0; i < 7; i++){
aKnappar[i].onRelease = function():Void {
aBilder[i]._visible = true;
}
}
}
Howcome this doesn't work? I'm trying simply to make 7 buttons that each has
the function to visible a corrensponding mc in the other array. What is the
basic error I'm doing? Can't understand why it isn't working.
Re: Array in an Array kglad
1/7/2007 3:25:32 PM
first, use the attach code option so your code doesn't get altered by this
forum.

second, your ith button (aKnappar[ i ]) doesn't know it's the ith button:
store the value i in a variable attached to each button. for example,
aKnappar[ i ].ivar=i.
Re: Array in an Array amilton22
1/7/2007 4:12:20 PM
Thanks, but I doesn't seem to work! I have flash 8? But kinda strange. Every mc
is defiend like in the array so no name miss.

The problem seems to be that now It doesn't make buttons out of my 7 imagest
defined in aKnappar. Do I need to define "myIndex" in a variable?
Re: Array in an Array amilton22
1/7/2007 4:23:38 PM
When I tried tracing it It displayed nothing within the function but the i
numbers when before the function. Numbers seem to be lost?

for(var i:Number = 0; i < 7; i++){
aKnappar.myIndex = i;
aKnappar.onRelease = function():Void {
trace([aKnappar.myIndex]);
aBilder[this.myIndex]._visible = true;
}
}
Re: Array in an Array kglad
1/7/2007 4:46:21 PM
amilton, you have no array index.

Re: Array in an Array amilton22
1/7/2007 5:00:55 PM
Yes finaly its working. Thanks alot both of you. I attached to code for future
losties.

for(var i:Number = 0; i < 7; i++){
aKnappar[i].ivar = i;
aKnappar[i].onRelease = function():Void {
aBilder[this.ivar]._visible = true;
}
}
Re: Array in an Array kglad
1/7/2007 5:57:00 PM
AddThis Social Bookmark Button