carmenMiranda
Programmer
I have some AS2 code that has a lot of duplication to control various buttons and MovieClips and was wondering if it's possible to streamline this code using a 'for' loop, like I would when attaching MovieClips dynamically.
Here's the code as it's currently written:
Can anyone show me how to construct the correct type of 'for' loop to streamline this code?
Here's the code as it's currently written:
Code:
//----------- INIT VARS -------------------------
var color01:String = "0xE24C9B";
var color02:String = "0x009BDB";
var color03:String = "0x50B848";
var color04:String = "0xF58220";
var base01:MovieClip = timer01_mc.timerBase_mc;
var base02:MovieClip = timer02_mc.timerBase_mc;
var base03:MovieClip = timer03_mc.timerBase_mc;
var base04:MovieClip = timer04_mc.timerBase_mc;
var btn01:Button = timer01_mc.rollBtn_btn;
var btn02:Button = timer02_mc.rollBtn_btn;
var btn03:Button = timer03_mc.rollBtn_btn;
var btn04:Button = timer04_mc.rollBtn_btn;
var bar01:MovieClip = timer01_mc.timerBar_mc;
var bar02:MovieClip = timer02_mc.timerBar_mc;
var bar03:MovieClip = timer03_mc.timerBar_mc;
var bar04:MovieClip = timer04_mc.timerBar_mc;
var url01:String = "[URL unfurl="true"]http://www.url01.com";[/URL]
var url02:String = "[URL unfurl="true"]http://www.url02.com";[/URL]
var url03:String = "[URL unfurl="true"]http://www.url03.com";[/URL]
var url04:String = "[URL unfurl="true"]http://www.url04.com";[/URL]
//-------------- BUTTON CONTROL -------------------------
btn01.onRollOver = function(){ baseCol01 = new Color(base01); baseCol01.setRGB(color01);
};
btn01.onRollOut = function(){ baseCol01 = new Color(base01); baseCol01.setRGB(0xCCCCCC);
};
btn01.onRelease = function(){ getURL(url01, "_blank");
};
btn02.onRollOver = function(){ baseCol02 = new Color(base02); baseCol02.setRGB(color02);
};
btn02.onRollOut = function(){ baseCol02 = new Color(base02); baseCol02.setRGB(0xCCCCCC);
};
btn02.onRelease = function(){ getURL(url02, "_blank");
};
btn03.onRollOver = function(){ baseCol03 = new Color(base03); baseCol03.setRGB(color03);
};
btn03.onRollOut = function(){ baseCol03 = new Color(base03); baseCol03.setRGB(0xCCCCCC);
};
btn03.onRelease = function(){ getURL(url03, "_blank");
};
btn04.onRollOver = function(){ baseCol04 = new Color(base04); baseCol04.setRGB(color04);
};
btn04.onRollOut = function(){ baseCol04 = new Color(base04); baseCol04.setRGB(0xCCCCCC);
};
btn04.onRelease = function(){ getURL(url04, "_blank");
};
Can anyone show me how to construct the correct type of 'for' loop to streamline this code?