Skip to main content
Participant
August 1, 2006
Answered

"if" statement problem...

This is maddening, but I must be missing something simple.
First, I have a frame that loads a variable from an ASP page which writes either "&checklist=1" if an email is entered or "&checklist=0" if the email is left blank:
quote:

sendVar = new LoadVars();
getVar = new LoadVars();
sendVar.email = email.text;
sendVar.sendAndLoad("send.asp", getVar, "POST");
getVar.onLoad = function(success) {
if (success) {
_root.checklist = this.checklist;
_root.gotoAndPlay("Go");
} else {
_root.response.text = "Error.";
}

Now on the next frame, I put up dynamic text with the "var" name as "_root.checklist". When the page pulls a "1", the text displays as "1".... when it pulls a "0", it displays a "0". So far, so good.

The problem is, I have a MC on the stage that I only want to be visible if "_root.checklist" is equal to "1". Here's what I came up with:
quote:


_root.myMC.onLoad = function(){
if (_root.checklist == 1){
_root.myMC._visible = true;
} else {
_root.myMC._visible = false;
}
}

I've also tried using "onClipEvent(load)" on the MC itself... I've tried taking the function part off, and just keeping it on the main timeline... I've tried putting the "if" statement first... among other things.

Here's a simplified example: Right here

or if you want: Download the files

I'd appreciated any help anyone could give... and I'll probably be slapping myself when I hear the answer.
This topic is closed to new replies. Start a new post to keep the conversation going.
Newsgroup_UserCorrect answer
Inspiring
August 1, 2006
tmat411,

> Sorry... the quotes are just my personal online
> affectation.

Devil is in the details, eh?

> The next frame has the dynamic text calling the
> variable _root.checklist, and it displays 0.

If the data is coming frmo a dynamic text field, then the data is a
string. In AS2, strong typing is only checked at compile time; it is not
enforced at runtime.

Try tracing the typeof value of _root.checklist ..

trace(typeof(_root.checklist));

... see what you get in the Output panel.

I should also mention -- sort of unrelated, but only sort of -- the
MovieClip.onLoad event is only useable with classes that extend MovieClip.
It seems perfectly reasonable that MovieClip.onLoad should be indentical to
onClipEvent(load), but it isn't. :-/


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."


4 replies

Inspiring
August 1, 2006
tmat411,

> Now on the next frame, I put up dynamic text with the
> "var" name as "_root.checklist". When the page pulls
> a "1", the text displays as "1"....

Bingo.

> when it pulls a "0", it displays a "0". So far, so good.

That's the answer, though. These variables are strings.

> The problem is, I have a MC on the stage that I only
> want to be visible if "_root.checklist" is equal to "1".

Still using quotes, so you're still dealing with strings. :)

> Here's what I came up with:
> _root.myMC.onLoad = function(){
> if (_root.checklist == 1){

Where are your quotes? At this point, you're testing against a number.
;)


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."


Translate
tmat411Author
Participant
August 1, 2006
Sorry... the quotes are just my personal online affectation.

I even tried to simplify it. On the main timeline, I strict type my checklist variable- var checklist:Number
Then on the button - _root.checklist =0; _root.gotoAndPlay("Go");
The next frame has the dynamic text calling the variable _root.checklist, and it displays 0.
The next frame has this:

quote:

_root.myMC.onLoad = function() {
if (_root.checklist == 1) {
_root.myMC._visible = true;
} else {
_root.myMC._visible = false;
}
};


except that myMC still shows. _root.checklist HAS to be a Number... and even if it isn't, myMC should be set to "_visible = false" by default. It should only set to "true" if _root.checklist is the actual integer 1.

It's blowing my mind. Here's the page again: http://www.vinylpop.com/flash/test.html
Translate