PDA

View Full Version : syntax help



deep cover
April 19th, 2002, 10:00 PM
I'm trying to write the Actionscript code that will move my MC to a certain point then reset. In other words, I want my MC to move left until it reaches -650 of the X position then start all over again fro 750 of the X position.

Here's the code I've written which doesn't work:

onClipEvent (enterFrame) {
_x-=2;
&nbsp &nbsp &nbsp &nbsp }
if (_x =-670
_X = 740

Any aid would be appreciated immensely.

I am not Jubba
April 19th, 2002, 11:05 PM
onClipEvent (enterFrame) {
_x -= 2;
if (_x = -670) {
_x = 740
}
}

eyezberg
April 20th, 2002, 01:14 AM
wrong! be carefull to use double equals when checking, else you set the variable!
Not: if (_x = -670) but if (_x == -670)!
And this check is dangerous, coz if your clip is not positioned on a full pixel (say _x=749.3) at the start, it will NEVER be equal to -670, you need to check for <= (less than or equal to) to make sure!

I am not Jubba
April 20th, 2002, 07:46 AM
doh! I know...i missed that...I just copied and pasted and I didn't realize...shame on me...:(

deep cover
April 20th, 2002, 02:41 PM
This is the code that isn't working:

onClipEvent (enterFrame) {
&nbsp &nbsp &nbsp &nbsp _x -= 5;
&nbsp &nbsp &nbsp &nbsp if (_x <== -670) {
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp _x = 0;
&nbsp &nbsp &nbsp &nbsp }
}

Here's the error message verbatim: "Scene=Scene 1, Layer=topheader, Frame=1: Line 3: Operator '<=' must be followed by an operand
&nbsp &nbsp &nbsp &nbsp if (_x <== -670) {"

Any further aid will be appreciated Eyezberg and/or I am not Jubba...

upuaut8
April 20th, 2002, 03:09 PM
onClipEvent (enterFrame) {
_x -= 5;
if (_x <= -670) {
_x = 0;
}
}

deep cover
April 20th, 2002, 03:47 PM
Thanks upuaut8.

That's strange. Ic had previously tried the code you provided, but it didn't work then. Now however it works.

I also came with a code to do the same action:

onClipEvent (load) {
&nbsp &nbsp &nbsp &nbsp speed -= 2;
&nbsp &nbsp &nbsp &nbsp left = -300;
&nbsp &nbsp &nbsp &nbsp right = 370;
}
onClipEvent (enterFrame) {
&nbsp &nbsp &nbsp &nbsp _x -= 2;
&nbsp &nbsp &nbsp &nbsp if (_x<=left) {
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp _x = right;
&nbsp &nbsp &nbsp &nbsp }
}

Thanks buddy...