0
votes

I am trying to convert the longer code i have below into shorter codes, the codes that i have is for Actionscript 2, while i am using as2 debugger, trace(), its getting the loop, however it will not recognize that is a movieclip (button1 - button3 are 3 different movie clips that i assigned).

from this

button1.onRollOver = function(){
m_bt1.scaleTo(70, 1, "easeoutelastic");
};

button1.onRollOut = function(){
m_bt1.scaleTo(100, 1, "easeoutelastic");
};

button2.onRollOver = function(){
m_bt2.scaleTo(70, 1, "easeoutelastic");
};

button2.onRollOut = function(){
m_bt2.scaleTo(100, 1, "easeoutelastic");
};

button3.onRollOver = function(){
    m_bt3.scaleTo(70, 1, "easeoutelastic");
};

button3.onRollOut = function(){
    m_bt3.scaleTo(100, 1, "easeoutelastic");
};

to this:

var $i;
for($i=1; $i <4; $i++){
    var main_bt = 'button'+$i;
    _root.main_bt.onRollOut = function(){
        this.main_bt.scaleTo(70, 1, "easeoutelastic");
    }
}
1

1 Answers

0
votes

Try putting buttons in array first and than iterating over array:

var buttons = [button1, button2, button3];
for(var index=0; index < buttons.length; index++){ 
    var main_bt = buttons[index]; 
    main_bt.onRollOut = function(){ 
        this.main_bt.scaleTo(70, 1, "easeoutelastic"); 
    } 
} 

Or following sould work too: var button = _root['button'+$i]