Hi there everyone,
Basically all I want to do is cut down my code so it’s a bit easier to use.
I have buttons that are called btn1, btn2, btn3, btn4, btn5…
I’m putting the script for rollovers in a frame action:
btn1.onRollOver = btn2.onRollOver = btn3.onRollOver = btn4.onRollOver = btn5.onRollOver = function() {
this.gotoAndStop("over");
};
Is there a way to make it simpler? It’d be easier if I could have it something like this:
btn**[COLOR="Red"](i)[/COLOR]**.onRollOver = function(){
this.gotoAndStop("over");
}
If anyone knows a way to do it I’d be very grateful.!
Cheers, Pdue
for (var i:Number = 0; i <= 5; i++) {
this["btn" + i].onRollOver = function() {
this.gotoAndStop("over");
};
}
Holy!!! That was seriously quick!!!
I’d been looking at for loops but couldn’t get them to work, this works perfectly, cheers mate!!
Pdue
Sorry to bother you again,
When one of the buttons is clicked, it sends all of the buttons to an ‘off’ state and then sets the clicked button to an ‘on’ state.
Is there a way to further shorten the next part?:
this["btn" + i].onRelease = function() {
btn1.gotoAndStop("off");
btn2.gotoAndStop("off");
btn3.gotoAndStop("off");
btn4.gotoAndStop("off");
btn5.gotoAndStop("off");
this.gotoAndStop("selected");
gotoAndStop(this._name);
};
Pdue
not really. Im sure you could use a function with a loop, but it will be just as long and look more confusing.
scotty
6
var curBtn;
for (var i = 0; i<=5; i++) {
var btn = this["btn"+i];
btn.onRelease = function() {
this.gotoAndStop("selected");
curBtn.gotoAndStop("off");
curBtn = this;
};
}
scotty(-:
Man, that’s sweet, I love flash sometimes!!!
Cheers guys, you da bomb!