Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 10-10-2002, 05:03 PM   #1
flx
Confused? I am....
 
flx's Avatar
 
Join Date: Aug 2002
Location: EaRTH
Posts: 90
Arrow What goes down - does not come up.

Take a look at this (please )....

ActionScript Code:
onClipEvent (enterFrame) {     if (this._y<=380) {         this._y += 10;     }     if (this._y>=380 and this._x<=530) {         this._x += 10;     }     if (this._X>=530 and this._y>=18) {         this._y -=10;     }     if (this._y<=18 and this._x>=20) {         this._x -= 10;     } }

Basically I was bored and decided to do a little bit of (simple) scripting. So i thought i'd make a lil blu circle and make it move around the stage.
With this script shown above
- the lil blu circle happily moves down the stage
- then once at the bottom it makes a journey to the right side of the stage.

However, once it has reached the right side it takes one step up and goes no futher.

... WHY?
flx is offline   Reply With Quote
Old 10-10-2002, 05:57 PM   #2
pom
Allez les Bleus!!!
 
pom's Avatar
 
Join Date: Oct 2002
Location: Paname
Posts: 2,493
Default

Hey man,
that's a classic with Flash 5
ActionScript Code:
if (this._y<=380) {                 this._y += 10;         }         if (this._X>=530 and this._y>=18) {                 this._y -=10;         }
When your clip has reached the bottom right position, this.y<=380 si false, and this._X>=530 and this._y>=18 is true, so you move up.

Next, both this.y<=380 and this._X>=530 and this._y>=18 are true, so you tell your movie to go up by 10 and down by 10.

You can solve that by using another variable (a boolean) to know whether you're going up or down, and another for the left/right motion.

pom

Last edited by pom; 10-10-2002 at 06:01 PM.
pom is offline   Reply With Quote
Old 10-10-2002, 06:16 PM   #3
flx
Confused? I am....
 
flx's Avatar
 
Join Date: Aug 2002
Location: EaRTH
Posts: 90
Lightbulb Ahhhh...

I was fooled by the one thing i was trying to avoid.. boy i feel .

Thanx for pointing out my mistake.
Till next time - take care..
flx is offline   Reply With Quote
Old 10-10-2002, 09:38 PM   #4
flx
Confused? I am....
 
flx's Avatar
 
Join Date: Aug 2002
Location: EaRTH
Posts: 90
Red face Once a FoOl, alwAyS a fOoL...

I thought I had something here .. but I guess not.
ActionScript Code:
onClipEvent (enterFrame) {     ydir = d;     xdir = r; } onClipEvent (enterFrame) {     if (this.ydir == d and this._y<=380) {         this._y += 10;         this.xdir = r;     }     if (this.xdir == r and this._y>=380 and this._x<=530) {         this._x += 10;         this.ydir = u;     }     if (this.ydir == u and this._X>=530 and this._y>=18) {         this._y -= 10;         this.xdir = l;     }     if (this.xdir == l and this._y<=18 and this._x>=20) {         this._x -= 10;         this.ydir = d;     } }

The same thing as before happens.. but i'm too to see the conflict. LoL. Well no doubt theres something wrong with my scripting .
Are the variables 'ydir' and 'xdir' not being changed?? Who knows..
So, I shall pass my woes on to you.
flx is offline   Reply With Quote
Old 10-10-2002, 10:29 PM   #5
pom
Allez les Bleus!!!
 
pom's Avatar
 
Join Date: Oct 2002
Location: Paname
Posts: 2,493
Default

Well, first thing: put only 1 enterFrame I supposed you wanted the first one to be an onLoad, right?

Second thing, why don't you use only one variable? That way you have less tests:
ActionScript Code:
onClipEvent (load) {     dir="d"; } onClipEvent (enterFrame) {     if (dir=="d" and _y<=380) {         _y += 10;         if (_y>=380) dir="r";         }     if (dir=="r" and _x<=530) {         _x += 10;         if (_x>=530) dir="u";     }     if (dir=="u" and _y>=18) {         _y -= 10;         if (_y<=18) dir="l";     }     if (dir=="l" and _x>=20) {         _x -= 10;         if (_x<=20) dir="d";     } }
pom
pom is offline   Reply With Quote
Old 10-11-2002, 06:09 PM   #6
flx
Confused? I am....
 
flx's Avatar
 
Join Date: Aug 2002
Location: EaRTH
Posts: 90
Default

Quote:
Originally posted by pom
[B]Well, first thing: put only 1 enterFrame I supposed you wanted the first one to be an onLoad, right?
Well actually.. in my confused logic i thought it would be better to put the variable in an 'enterframe' event - that way it would be updated continuosly. Well thinking about it now i guess you dont have to.

So, does having two 'enterFrame' events mess things up? I just did that to keep it tidy.

*sighs* it's so hard being me and boredom isn't as simple as it used to be
flx is offline   Reply With Quote
Old 10-11-2002, 07:02 PM   #7
pom
Allez les Bleus!!!
 
pom's Avatar
 
Join Date: Oct 2002
Location: Paname
Posts: 2,493
Default

First rule of the fight club: Never have 2 enterFrames at the same time. Unclear, and unnecessary (you can put everything in one...)

Second rule of the fight club: Well, I don't see why you would need to set the directions to right/down all the time...

pom
pom is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:17 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.