all groups > flash actionscript > august 2005 >
You're in the

flash actionscript

group:

Help with Arrays


Help with Arrays Hoathy
8/26/2005 7:19:12 PM
flash actionscript: I want to be able to cut my actionscripts down a little by changing large
scripts like this:

_global.ANYVALUE = function(){
PA1.gotoAndStop(2);
PA2.gotoAndStop(2);
PA3.gotoAndStop(2);
PB3.gotoAndStop(2);
PB5.gotoAndStop(2);
}

into something simple, like an array that adds '.gotoAndStop(2);' onto each
value, then outputs it into the actionscript to be excuted (like the function
example)

I'm not very effcient at coding, but array's seem like the solution. Can
somebody help me out please? (I need some code)

Thank you for your time
Re: Help with Arrays bwm_razel
8/26/2005 7:27:21 PM
myArray = ["PA1","PA2","PA3","PA4","PA5"]

for (var i in myArray) {
myArray.gotoAndStop(2);
}

That populates the array with your PAx things, then the for loop cycles
through the array, and makes everyone gotoAndStop at their second frame. You
can run that off a conditional, or do whatever with it.

So, using your global variable, I would say:

_global.ANYVALUE = function() {

myArray = ["PA1","PA2","PA3","PA4","PA5"]

for (var i in myArray) {
myArray.gotoAndStop(2);
}
}
Re: Help with Arrays bwm_razel
8/26/2005 7:28:19 PM
Re: Help with Arrays Hoathy
8/26/2005 7:29:40 PM
Re: Help with Arrays bwm_razel
8/26/2005 7:33:39 PM
Hell I found out why the second half was in italics. Also, it means my code is
wrong.

Here, do this instead:


_global.ANYVALUE = function() {

myArray = ["PA1","PA2","PA3","PA4","PA5"]

for (var i in myArray) {
myArray[ i ].gotoAndStop(2);
}
}

You need the "[ i ]" after myArray in the second line...apparently not putting
spaces in between the brackets made my post italicized.

Re: Help with Arrays Have A Banana
8/26/2005 7:54:06 PM
Hello,

Here on the forums, it looks for formatting tags. putting the i in brackets
causes the following text to come out in italics (as you found out). It was
suggested to me that whenever you need to put a loop with an array access that
you use the variable 'n' instead.

Hope that helps!
AddThis Social Bookmark Button