PDA

View Full Version : this._x AS help


Jreeter
02-29-2004, 03:43 PM
Hi, guys first id like to say im learning flash and this site rocks im loving action script now.. but i was fiddling through some noob tutorials and found the one on simple animation with as heres what i want.


onClipEvent (enterFrame) {
// when it hits frame1 this(mc) does this below.
this._alpha = random(100);
if (this._x<200) {
this._x += 5; } else {
this._x -=5;
}

}

so i was fiddling around and started mixing as code
what i want it to do is after x reaches 200 i want it to go back hence why i put this._x -=5; im not sure but i know in vb code else would usually be a then statement if i remember.

divarch
02-29-2004, 03:52 PM
And what is the problem?
In your code say _x reaches 190, then 195 then 200, and then 205, now it jumps to 'else' and goes back to 200, but now it jumps back to 'if' and goes to 205, and over and over again, so it's stuck at 200.

I hope that clearify things a bit
Welcome to the forum

Jreeter
02-29-2004, 04:21 PM
the problem is that it doesnt go back -5
as soon as it hits 200 mark i want it to start
going back to starting point which is -5 but i want it
slide back.

divarch
03-01-2004, 11:40 AM
Hi there, sorry for the late response.
In that case you will need a bit different approach. The following will bounce between left-right edges:
var leftEdge = 0;
var rightEdge = 300;
var speed = 5;
box.onEnterFrame = function() {
this._x += speed;
if (this._x>rightEdge||this._x<leftEdge) {
speed = -speed;
}
};
Cheers

Jreeter
03-03-2004, 04:32 PM
ty