creating button functions in for loop?

  • BooGiE_MaN
  • Proficient
  • Proficient
  • User avatar
  • Joined: Jun 05, 2005
  • Posts: 387
  • Loc: Cape Town, South Africa
  • Status: Offline

Post October 4th, 2009, 2:03 am

i have a series of buttons in a movie and I want to each to have the same functions applied to them without typing out endless code.

I tried
Code: [ Select ]
for(i=1;i<8;i++){
    var butname = "button"+i;
    butname.useHandCursor = false;
        butname.onRollOver = function(){
        showCursor();
        }
        butname.onRollOut = function(){
        hideCursor();
        }
}
  1. for(i=1;i<8;i++){
  2.     var butname = "button"+i;
  3.     butname.useHandCursor = false;
  4.         butname.onRollOver = function(){
  5.         showCursor();
  6.         }
  7.         butname.onRollOut = function(){
  8.         hideCursor();
  9.         }
  10. }

I'm not sure if it is now looking for an instance called "butname" and not "button1", "button2", etc
Any ideas?

Simply Links Directory
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post October 4th, 2009, 2:03 am

  • BooGiE_MaN
  • Proficient
  • Proficient
  • User avatar
  • Joined: Jun 05, 2005
  • Posts: 387
  • Loc: Cape Town, South Africa
  • Status: Offline

Post October 4th, 2009, 2:23 am

found the answer
Code: [ Select ]

for(var i=1;i<9;i++){
    
    var butname = "button"+i;
    trace(butname);
    _root[butname].useHandCursor = false;
        _root[butname].onRollOver = function(){
        showCursor();
        }
        _root[butname].onRollOut = function(){
        hideCursor();
        }
}
  1. for(var i=1;i<9;i++){
  2.     
  3.     var butname = "button"+i;
  4.     trace(butname);
  5.     _root[butname].useHandCursor = false;
  6.         _root[butname].onRollOver = function(){
  7.         showCursor();
  8.         }
  9.         _root[butname].onRollOut = function(){
  10.         hideCursor();
  11.         }
  12. }

Simply Links Directory
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Joined: May 28, 2003
  • Posts: 23407
  • Loc: Woodbridge VA
  • Status: Offline

Post October 4th, 2009, 6:19 am

Thanks for sharing the solution. Always nice to find the answer on your own
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 27 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.