PDA

View Full Version : if statement to check condition


hipjimmer
10-03-2007, 02:23 AM
I've got a number of layers in my fla. One of them has a watermark (its a mc) on it that shows if the account is not active. I have moved the code to the MC as a last resort as I for the life of me can't understand why I can't make this MC vanish when the value a "is_active" field is true. The values in the traces indicate the values are what I would expect. Someone please enlighten me.

onClipEvent (enterFrame) {
this._visible = true;
trace ("agent is active is -> " + _level0.agent_is_active);
if (_level0.agent_is_active) {
trace("setting visibility to false");
this._visible = false;
}
}

CyanBlue
10-03-2007, 03:13 AM
Howdy and Welcome... :)

You have to be abit more specific in your if statement like this...
onClipEvent (enterFrame) {
this._visible = true;
trace ("agent is active is -> " + _level0.agent_is_active);
if (_level0.agent_is_active != "is_active") {
trace("setting visibility to false");
this._visible = false;
}
}
Oh, you can use AS tag to format the code... ;)

hipjimmer
10-03-2007, 03:15 AM
But in _root I've already defined agent_is_active as a boolean. And the traces actually render as true or false. What gives?

CyanBlue
10-03-2007, 03:18 AM
Oh... What do you get if you do this??? Can you copy and paste???
onClipEvent (enterFrame) {
this._visible = true;
trace ("agent is active is -> " + _level0.agent_is_active);
if (_level0.agent_is_active) {
trace ("\tagent is active is true.");
trace("\tsetting visibility to false");
this._visible = false;
}
else
{
trace ("\tagent is active is false.");
}
}

hipjimmer
10-03-2007, 03:29 AM
I get this uncanny result:

agent is active is -> false
agent is active is true.
setting visibility to false

huh?

CyanBlue
10-03-2007, 04:27 AM
Um... Please don't bump the thread... That's not nice and is not allowed in this town... :(

Try this and tell me what you get...
onClipEvent (enterFrame) {
this._visible = true;
trace ("agent is active is -> " + _level0.agent_is_active + " : type = " + typeof(_level0.agent_is_active));
if ((_level0.agent_is_active == true) || (_level0.agent_is_active == "true")) {
trace ("\tagent is active is true.");
trace("\tsetting visibility to false");
this._visible = false;
}
else
{
trace ("\tagent is active is false.");
}
}

hipjimmer
10-03-2007, 04:32 AM
agent is active is -> false : type = string
agent is active is false.
agent is active is -> false : type = string
agent is active is false.
agent is active is -> false : type = string
agent is active is false.
agent is active is -> false : type = string
agent is active is false.

String?

CyanBlue
10-03-2007, 04:35 AM
Well... That's what your script says you have... Either use it as a string or try to find the reason why it is string instead of a boolean... Up to you... ;)

hipjimmer
10-03-2007, 04:37 AM
Thanks for the help, the behavior is at least correct now and the pressure is off. I'll hunt down where it may be getting cast differently.

CyanBlue
10-03-2007, 04:40 AM
Cool... Don't forget to post what you find out... ;)

tg
10-03-2007, 04:38 PM
for this whole script, i wouldnt even use an if statement.
you want visible to be true, or false based on your boolean variable. so let the variable set your visibility.... dont ask if, then set visible.

do it like this:

this._visible = !_level0.agent_is_active;

so, if agent is active is true, visible is false.
if agent is active is false, then visible is true.

also, i personally wouldnt set this into an onEnterFrame event, but that is just how i work my code.
i use data events, or interactions to control control any event in my code.

hipjimmer
10-03-2007, 05:59 PM
Thanks for the insight, where can I find out more on data events?

Also, the reason for moving the code to the clip event was a timing issue problem I was having. Main time line goes something like this:

1. Load XML data
2. GOTO a slide player named frame

What was happening was the water mark would not appear (if it should) the first time I hit the slide frame. But, if I went to the menu and then back the water mark appeared.

I'm thinking I have a mc instantiation timing issue that the on clip event (cheaply) fixed for me.

Any insight would be appreciated on the root cause of that.

tg
10-03-2007, 07:38 PM
so when is the value of agent is active changed?
when that changes, that is when you want to change the value of your _visible.

what triggers that change?

hipjimmer
10-03-2007, 09:00 PM
It only changes when I assign the value that comes in from the XML I read in. Once loaded I set "agent_is_active" to the value of the xml attribute "is_active".

I'm thinking the mc has not hit the stage yet early on. Frame 1 & 2 are mostly actions, preload etc, and once the playhead passes where the mc is needed, it can set the visible property. Just my guess.

I can't export it for action script as it's already on the stage already right?