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/
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.
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.
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?
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; } }
amilton, you have no array index.
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; } }
Don't see what you're looking for? Try a search.
|