Reputation: 13
I am using this script on my button:
on(release){
var body2:Boolean = true;
answerField = body2
var body1:Boolean = false;
var body3:Boolean = false;
gotoAndStop(2);
}
And this script on my second button:
on (release) {
if (body1=true) {
gotoAndStop(4);
} else if (body2=true) {
gotoAndStop(5);
} else {
gotoAndStop(6);
}
}
However for some reason I can not get my second button to take me to frame 5 even when body2=true.
Any advice?
Upvotes: 0
Views: 592
Reputation: 9839
Your code is not working because simply you are using an assignment operator ( =
) instead of the comparison one ( ==
) in your if
statements which they can be :
if (body1 == true) { // you can write it : if(body1){}
gotoAndStop(4);
} else if (body2 == true) { // you can write it : if(body2){}
gotoAndStop(5);
} else {
gotoAndStop(6);
}
For more about ActionScript operators, take a look here.
Also, your Boolean
s should be declared globally using _global
to be accessible everywhere in your code, or in your main timeline to be accessible using _root.my_var
, and when they are declared inside a MovieClip or Button code, you can call them, for example, using _root.my_button.myvar
...
So in your case, supposed that your first button is called button1
, the code of your other button can be like this :
if (_root.button1.body1) {
gotoAndStop(4);
} else if (_root.button1.body2) {
gotoAndStop(5);
} else {
gotoAndStop(6);
}
Edit :
Example of using _global
:
code on button1
:
on (release) {
_global.body2 = true;
_global.body1 = false;
_global.body3 = false;
}
code on button2
:
on (release) {
trace(body2); // gives : true
trace(body1); // gives : false
}
Hope that can help.
Upvotes: 2