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
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); } }
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.
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!
Don't see what you're looking for? Try a search.
|