-
Hi,
I'm fairly new to Flash 5, but I know the basics. But i cannot figure this out.
It seems simple - I have Button A. On the other side of the page I have various other buttons, lets say Buttons 1-8 (these buttons are movie clips with ON and OFF states).
What I want to do is when button A is rolled over, I want to highlight certain buttons of 1-8.
Doing just one is no problem:
on (rollOver) {
tellTarget ("_root.A1") {
gotoAndPlay (6);
}
}
on (rollOut) {
tellTarget (_root.A1) {
gotoAndStop (1);
}
}
But I cannot get started on how to do more than one. Furthermore, there will actually be buttons B and C too - and each button (a b and c) will light up different buttons of the 1-8 variety depending. I imagine I need to set some variables in button a, but from there - I'm l ost...
HELP!
Tom
-
first, I'll simplify your code with dot syntax, which has replaced the need for Flash 4's 'tellTarget' syntax:
on(rollOver){
_root.A1.gotoAndPlay(6);
}
isn't that better? Now to do that with many buttons just add more code!!
on(rollOver){
_root.A1.gotoAndPlay(6);
_root.A2.gotoAndPlay(6);
_root.A3.gotoAndPlay(6);
etc.
}
But if you want to handle a large amount of movieclips easier, you should use a for loop, and the 'eval' statement, which evaluates a string and treats it like a variable. Watch:
on(rollOver){
for(var z=1;z<=8;z++)
{
eval("_root.A"+z).gotoAndPlay(6);
}
}
Flash will take "_root.A"+z and evaluate it as a variable. So when z is 1, at the beginning of the loop, Flash will see eval("_root.A"+z) as '_root.A1'.
Hope this helps!
-
Thanks Lux!
I know JavaScript quite well so this all makes perfect sense. I really need to just learn to get around in ActionScript.
Now here's the thing: Say I have these 8 buttons. I could do the FOR loop like you suggest (In fact I was just doing that when you replied), but here's the problem:
One object will want to roll over buttons 1,6,7 and 8
another will want to roll over buttons 4,6,7
and so on...now I can't step through 1 to 8 because not all of them can be on, only some.
I'm going to have like 9 of these objects that are going to need to trigger these buttons. I guess I could do each one like thus:
on(rollOver){
_root.A1.gotoAndPlay(6);
_root.A6.gotoAndPlay(6);
_root.A7.gotoAndPlay(6);
_root.A8.gotoAndPlay(6);
}
and so on. I would have to make the different statements for all 9, and I can do that - I'm just wondering if there is an easier way using variables...(globals) somehow.
also, quick question:
rollOver works fine, but what about being able to click it on and off instead - I tried using on(press) but It didn't work right....how would you do it if you wanted to click the mouse to turn them on, and then click again to turn them off?
Thanks a TON.
Tom
-
well you're in luck with Flash 5, the actionscript is based on the same ECMA standards javascript is! :)
for the flip on/off, try using on(release) instead of on press, and just flip a boolean.
here's what I do when I want to run series is select mcs:
actionArray = new Array(2,4,6,7);
for (z=0;z<actionArray.length;z++)
{
eval("_root.A"+actionArray[i]).gotoAndPlay(8);
}
You just have an array that defines the ones you want to flip, and for loop through that array! :)
cheers!
-
Awesome idea Lux...yer the man. Thanks again for the help I really really appreciate it! :)
I've got this project due in one week and I'm pretty new to Flash, so this is a big boon. Checked out your site btw and was very impressed, going to go back and explore when I have some time.
Cheers
Tom