creating button functions in for loop?

  • BooGiE_MaN
  • Proficient
  • Proficient
  • User avatar
  • Posts: 387
  • Loc: Cape Town, South Africa

Post 3+ Months Ago

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?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • BooGiE_MaN
  • Proficient
  • Proficient
  • User avatar
  • Posts: 387
  • Loc: Cape Town, South Africa

Post 3+ Months Ago

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. }
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

Thanks for sharing the solution. Always nice to find the answer on your own

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 7 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.