Answered
Simple(?) problems with "IF" statements and variables! Please help...
Nested a couple of layers down into my movie, I've got a form
with 2 blank fields and a checkbox, and a Submit button (the Submit
button actually just plays a clip rather than any actual
server-side submitting).
What I WANT to have happen is for the clip NOT to play unless ALL 3 elements have been "utilised", ie: BOTH the fields to have SOME copy in and for the checkbox to be ticked.
If ALL 3 criteria HAVE been met, then the clip should play.
Before we get to this form, 3 variables are set further back in the timeline, up a couple of levels:
step4a = "";
step4b = "";
step4e = "off";
Back in my form, the 2 blank fields have "Var"s called step4aName and step4bEmail.
Clicking the checkbox button sets the variable step4e to "on"
The following code is attached to the Submit button:
on (release) {
// FIRST VARIABLE IS SET TO MATCH FIRST FIELD
_parent._parent.step4a = step4aName;
// SECOND VARIABLE IS SET TO MATCH SECOND FIELD
_parent._parent.step4b = step4bEmail;
// TRACE COMMANDS FOR ERROR CHECKING
trace ("step4a = " + _parent._parent.step4a);
trace ("step4b = " + _parent._parent.step4b);
trace ("step4e = " + _parent._parent.step4e);
// ONLY PLAY CLIP IF BOTH FIELDS ARE FILLED AND BOX IS TICKED
if ((_parent._parent.step4a != "") &&
(_parent._parent.step4b != "") &&
(_parent._parent.step4e == "on")) {
this.play ();
}
}
When I test the movie, I get the following output (which is what I would expect, implying all is well):
step4a =
step4b =
step4e = off
Now what happens when I run this is that the clip will, quite correctly, NOT play if I just hit Submit without doing anything else first. But the problem comes when I ONLY tick the checkbox and then hit Submit, because then the movie clip DOES play, when it is NOT supposed to. Why? My two fields ARE still blank, as is proven by the trace commands I can see outputted when I hit the Submit button – they still say:
step4a =
step4b =
To further complicate things, if I DO type something into the 2 fields, but I then delete what I've typed, then the movie clip will correctly NOT play (with the checkbox ticked). The two variables outputted still say:
step4a =
step4b =
(And if I type some text into the 2 text fields, then the 2 traced variables outputted DO update to contain text that matches what I type in.)
So according to the output I'm seeing, the way I've put it together SHOULD work, but it doesn't.
So to sum up, the problem is, if I LEAVE my 2 fields totally blank, as it first appears on screen, then my error-checking doesn't work.
If I type something in my fields and then MAKE them blank by deleting the text in them, then my error-checking works as it should.
What's up with that?
What I WANT to have happen is for the clip NOT to play unless ALL 3 elements have been "utilised", ie: BOTH the fields to have SOME copy in and for the checkbox to be ticked.
If ALL 3 criteria HAVE been met, then the clip should play.
Before we get to this form, 3 variables are set further back in the timeline, up a couple of levels:
step4a = "";
step4b = "";
step4e = "off";
Back in my form, the 2 blank fields have "Var"s called step4aName and step4bEmail.
Clicking the checkbox button sets the variable step4e to "on"
The following code is attached to the Submit button:
on (release) {
// FIRST VARIABLE IS SET TO MATCH FIRST FIELD
_parent._parent.step4a = step4aName;
// SECOND VARIABLE IS SET TO MATCH SECOND FIELD
_parent._parent.step4b = step4bEmail;
// TRACE COMMANDS FOR ERROR CHECKING
trace ("step4a = " + _parent._parent.step4a);
trace ("step4b = " + _parent._parent.step4b);
trace ("step4e = " + _parent._parent.step4e);
// ONLY PLAY CLIP IF BOTH FIELDS ARE FILLED AND BOX IS TICKED
if ((_parent._parent.step4a != "") &&
(_parent._parent.step4b != "") &&
(_parent._parent.step4e == "on")) {
this.play ();
}
}
When I test the movie, I get the following output (which is what I would expect, implying all is well):
step4a =
step4b =
step4e = off
Now what happens when I run this is that the clip will, quite correctly, NOT play if I just hit Submit without doing anything else first. But the problem comes when I ONLY tick the checkbox and then hit Submit, because then the movie clip DOES play, when it is NOT supposed to. Why? My two fields ARE still blank, as is proven by the trace commands I can see outputted when I hit the Submit button – they still say:
step4a =
step4b =
To further complicate things, if I DO type something into the 2 fields, but I then delete what I've typed, then the movie clip will correctly NOT play (with the checkbox ticked). The two variables outputted still say:
step4a =
step4b =
(And if I type some text into the 2 text fields, then the 2 traced variables outputted DO update to contain text that matches what I type in.)
So according to the output I'm seeing, the way I've put it together SHOULD work, but it doesn't.
So to sum up, the problem is, if I LEAVE my 2 fields totally blank, as it first appears on screen, then my error-checking doesn't work.
If I type something in my fields and then MAKE them blank by deleting the text in them, then my error-checking works as it should.
What's up with that?