all groups > flash actionscript > february 2004 >
You're in the

flash actionscript

group:

I wanna use Use array to make my life easier...help


I wanna use Use array to make my life easier...help uncle_3than
2/5/2004 11:57:35 PM
flash actionscript:
I'm trying to make my bottons to do bunch of same thing over and over, and I have 4 buttons, I want them to be in an Array, here's what I originally wrote in a old fashioin say

ActionScript:
btn1.onRelease = function(){
trace("btn1 clicked");
}
btn2.onRelease = function(){
trace("btn2 clicked");
}
btn3.onRelease = function(){
trace("btn3 clicked");
}
btn4.onRelease = function(){
trace("btn4 clicked");
}




but now I want to try to put it in array

ActionScript:
myBtns = [btn1, btn2, btn3, btn4];





what I wanna do is to use this array and control my btns, like if myBtns[0] is click, the trace for btn and btn2-4 do somthing else, is there anyway that I can use if else statement to make one btn do one thing and other 3 btns do somthing else?..

somthing like:
ActionScript:
myBtns.onRelease = function(){
if(myBtn == 0){
do this
myBtn[1, 2, 3] do somthing else...
}
}





I know this example sucks but I just want to learn how to do this..thanks a lot for your help..


Re: I wanna use Use array to make my life easier...help Matheus
2/6/2004 8:07:51 AM
You can use prototype too!

Button.prototype.onRelease = function() {
trace(this._name + " clicked);
}


"uncle_3than" <webforumsuser@macromedia.com> escreveu na mensagem
news:bvul9f$6lh$1@forums.macromedia.com...
[quoted text, click to view]
I have 4 buttons, I want them to be in an Array, here's what I originally
wrote in a old fashioin say
[quoted text, click to view]
myBtns[0] is click, the trace for btn and btn2-4 do somthing else, is there
anyway that I can use if else statement to make one btn do one thing and
other 3 btns do somthing else?..
[quoted text, click to view]

Re: I wanna use Use array to make my life easier...help Jeckyl
2/6/2004 11:21:34 AM
something like this may work..

for (var x in myBtns) {
myBtns[x].onRelease = function() {
trace(this+" clicked");
}
}

the things that is making it tricky is that the script for the functions is
different for each function. That's not something you can directly code ..
that's why I changes your script a little so each button will use the same
script.

AddThis Social Bookmark Button