Skip to main content
Inspiring
December 19, 2006
Question

if() and else{}

  • December 19, 2006
  • 10 replies
  • 809 views
I'm making some invisible buttons which on rollover move a movieclip left and right. i have the code ( as good as i can do anyway )
but now im having problems with stopping it moving when it reaches a certain spot..

i tried the if and else commands, but they didnt work the way i typed them ( which I think is wrong )
i don't know how to use the greater than (>) symbol, i think thats the place im getting it wrong.
This topic has been closed for replies.

10 replies

SketchstaAuthor
Inspiring
December 20, 2006
Hey David yeah it was down to simple Logic. I had the if() statements in the rollOver actions, when they should have been in the functions being called by the rollOver action..

i got them right now, it works.

I just needed some sleep, i think. =)

Thanx alot to both of you for the help.
Inspiring
December 19, 2006
Sketchsta,

> hold on.. just incase im not being clear.

It's tough, isn't it? Programming is hard. ;)

> on rollOver i want the pestSlide to move, but i want it
> to stop moving when it reaches a certain spot.

Gotcha.

> The code you and David helped me with, stops it moving,
> if i rollover again after it moves past the _x position

Really, this comes down to a matter of sequence and logic. Every single
time slideRight is rolled over, the if() statement is asked the same
question. If the answer is yes, it does one thing; if not, it does another.

In one of .:}x-=V!P=-x{:.'s recent messages, the expression evaluated by
the if() statement was this:

!pestSlider._x<=-300

... which translates to "not pestSlider's _x property
less-than-or-equal-to -300"; in other words, "If it is *not true* that
pestSlider's _x property is equal to or less than -300". You see what's
going on? The exclamation point (!) negates things. So instead of asking
if something is greater than (or equal to) something else, you're asking the
opposite of that: namely, if one value is less than something else.

I recommend you look up the term "operators" in the ActionScript 2.0
Language Reference and look through all the ones that look like punctuation.
Honestly, what you're after is as easy as thinking through exactly what you
want, then using the right operator (or combination of operators) to state
that desire.


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


SketchstaAuthor
Inspiring
December 19, 2006
heres the .swf
this should explain better than i can.. =)

http://icg.awardspace.com/FLA/pest.html

I want it to stop when it reaches Rodents, when it scrolls left... and i want it to stop on Cockroaches when it scrolls right..
SketchstaAuthor
Inspiring
December 19, 2006
hold on.. just incase im not being clear.

on rollOver i want the pestSlide to move, but i want it to stop moving when it reaches a certain spot.
The code you and David helped me with, stops it moving, if i rollover again after it moves past the _x position i specify.

it starts from 100, and i want it to scroll until it reaches -700.
when i rollover at _x 100, it scrolls ( good) but it keeps scrolling forever, until i rollOut()
SketchstaAuthor
Inspiring
December 19, 2006
thats still not stopping it.

why put the exclamation ( ! ) before the mc name??
SketchstaAuthor
Inspiring
December 19, 2006
Thanx V!P, =)
but i'm trying to stop it when it reaches the _x value.
Participating Frequently
December 19, 2006
ah ok fixed !
Participating Frequently
December 19, 2006
try this
SketchstaAuthor
Inspiring
December 19, 2006
i just tried this:

slideRight.onRollOver=function(){
repeat=setInterval (moveRight,1);
if (pestSlider._x>-700) {clearInterval(repeat);}
else {repeat=setInterval (moveRight,1);}
slideRight.useHandCursor = false;
updateAfterEvent();}

it didnt work as you can probably tell. You would be able to see straight away what i did wrong.
with the code you helped me with i was able to use trace() and I found out the right co-ordinates too

it would be soo much easier for a newbie like me if i had a
when() statement.. =P
SketchstaAuthor
Inspiring
December 19, 2006
Hey David, thanx for the reply.

yeah that did it thanx. =)

but i think i might be on the wrong track here. ( reading your explanation made me see that )
this code now does what it's supposed to. but i want it to stop when it reaches -300.
the way it is now, it will not move if it's -300 or greater, so technically it stops. but this happens ONLY if i rollover the button again.

basically, i want it to move until it reaches -300, then stop.

sorry if i'm not making much sense, it's 4:30AM here, and i havent slept longer than about 5 hours in the last 2 days. =)
Inspiring
December 19, 2006
Sketchsta,

An if() statement evaluates an expression that must (sooner or later)
resolve to either true or false. Let's take a look at your code ...

> slideRight.onRollOver=function(){
> if(pestSlider = _x>-300){

I think I know what you're after, here. You're hoping to check if
pestSlider's MovieClip._x property is greater than 300, right? If that's
it, you need to reference the pestSlider instance's unique value for that
property. First, you reference the object itself, pestSlider, then you put
a dot, then you reference the property ...

pestSlider._x

... and that will resolve to a number (whatever value the _x property
currently holds for that object). Now, you'll need to compare that number
to -300. The combined expression will either be true or false, because the
_x value will either be greater than -300 or it won't be.

if (pestSlider._x > -300) { ... }


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