Hey Zaac,
 
var buttons = [home_btn, benefits_btn, aboutUs_btn];
var i = buttons.length;
var curBtn;
 
while( i-- ){
    buttons[i].>}
 
function btnRollOver(){
    this.gotoAndPlay("RollOver");
}
 
First thing to notice is it is better to use actual references to the buttons in the first place rather than evaluating strings all the time.
Second, create the function outside the loop then just refence the function. This is better for memoy management as the function is only defined once.
The while(i--) is simply counting backwards from the length of your array. When it gets to 0 - it stops. This is the fastest type of loop you can use.
 
Hope this is of some use. :)
 
Mike
 
 
----- Original Message -----
Sent: Tuesday, April 20, 2004 5:29 PM
Subject: [fugli] creating functions in a for loop

yo flashers,

have a menu in flash and trying to loop over each of the buttons and create the rollover function for each of them as a function. having problems to get it happen with the current code .... should i be going about it another way (is there a better way to do it)...

 

// create a list of all the buttons

buttons = ["home","benefits","aboutUs"];

currentButton = 0;

 

// this loop will create the function to go to the rollover state for each of the buttons

for (currentButton; currentButton<4; currentButton++) {

     

// the name of the current button

      tempCurrentButton = buttons[currentButton];

     

      // roll over button effect

      _root[buttons[currentButton]+"_btn"].onRollOver = function () {

            _root[tempButton+"_btn"].gotoAndPlay(tempCurrentButton+"RollOver");

      }

}

---
You are currently subscribed to fugli as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
http://www.mxdu.com/ + 24-25 February, 2004
---
You are currently subscribed to fugli as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
http://www.mxdu.com/ + 24-25 February, 2004

Reply via email to