Movieclip plays - despite condition!
I have a movie with 2 buttons - button1 and button2.
Each button is a movieclip and consists of 2 layers :
Layer 1 contains an 11-frame animation which fades
the text "button 1" up and down through tweening
the alpha from 30 to 100 and back to 30 again.
Layer 2 contains a button with alpha set to 0, this
button spands through the entire animation. The button
is assigned actions that moves the playhead to the
appropriate locations in the animation, when on(rollOver)
and on(rollOut)-events occur; making the text "button 1"
light up when the mouse goes over it, and fades it out
to alpha 30 when the mouse goes away.
This all works very good, but I also want to keep the button
"turned on" when I press it. So I create another layer in my
main movie - on top of the layer with the button in it.
In this layer I create a movie clip with the text "button 1"
in it, and make 2 frames; frame 1 with the alpha set to 0 and
frame 2 with the alpha set to 100 - both frames are assigned
the stop-action. I call the instance of this movieclip "button1On".
Now when the on (press) event on button 1 occurs, the actions
in button 1 tell the playhead in "button1On" to go to frame 2 -
and "turn on" the button by setting it to alpha 100. This works
well too.
Now comes the problem :
I want to have another button in my movie ; "button 2" and I want
thês button to do the same thing as "button 1" - no problem, I
create another button. However, if "button 1" is turned on -
(which means that the playhead in the movieclip "button1On" is placed in frame 2), then I want the on (press) handler in "button 2"
to turn "button 1" off. So I assign the following script to button 2:
on (press) {
if (_root.button1On._currentframe = 2) {
_root.button1On.gotoAndStop(1);
}
}
Great! - It works! - when "button 1" is on, and I press "button 2" -"button 1" is turned off!
Now let´s spice it up a bit: What if I want a little animation to play, when I press "button 2", say...an animation showing "button 1" slowly turning off? Well..I make a movieclip showing a fading "button 1" I place it on a separate layer and name the instance of it "button1TurnOff" and I am ready to go!
Hey!
Wait a minute!...naturally this animation should only play if and ONLY if "button 1" is on - so I include the script to play "button1TurnOff" in the if-statement - the script in "button 2" now looks like this:
on (press) {
if (_root.button1On._currentframe = 2) {
_root.button1On.gotoAndStop(1);
_root.button1TurnOff.gotoAndPlay(2);
}
}
This also works: When "button 1" is on, and I press "button 2"
"button 1" not only turns off, but the animation "button1TurnOff"
plays as well! The only problem is....when I press the "turned on" button 2, the animation "button1TurnOff" plays again!???
How can this be?? The if statement checks to see if
"button1On" is in frame 2, which it isn´t, because we set the playhead to frame 1 with the first press on "button 2"?? But this condition is ignored and the clip "button1TurnOff" plays again?
Can anyone explain this?? Please!!
P.S: I included the .fla for you to see!
|