"movement using actionscript" prob

I was reading the tutorial in this site about movement using actionscript, here is the url if any one wants it…

http://www.kirupa.com/developer/mx/ASmovement.asp

the tutorial is really amazing :slight_smile: the only thing i was wondering about is if it is possible to make the box (example used in url) stop at a certain point instead of just going further…
i reaaallly would love to know if i can do that…! thank you and i i’d appreciate ne help :slight_smile:

Happy New Year<:}

Yeah, you will need to declare in if statement for that.

That would go something like this…

onClipEvent(enterFrame) {
     speed = 1;
     this._x += speed;
<B>if(this._x>=200) {
this._x = 200;
}</B>
}

That says that if the _x location of the clip is greater than or equal to 200 pixels then it should day at 200 pixels, hence… stopping it there :slight_smile:

wow!! it works :slight_smile:
thank you sooo much!! i didnt expect an answer soo fast, thanks again :slight_smile:

cheers!

No problem man :slight_smile:

i got one more question i’d like to ask if u dont mind! :slight_smile:

u c lets say i have a rectangle and i assigned this AS to it…

onClipEvent(enterFrame) {
speed = 100;
this._x += speed;
if(this._x>=0) {
this._x = 0;
}
}

and after it is done going to that place i’d want it to go down…
i know that i havta change the _x to _y but what i mean is what do i do so that after it reaches the _x destination then it starts to accomplish the _y position…? its sounds confusing i know :stuck_out_tongue:
thank u

Something along the lines of…

onClipEvent (enterFrame) {
	speed = 5;
	this._x += speed;
	if (this._x>=200) {
		this._x = 200;
		this._y += speed;
		if (this._y>=200) {
			this._y = 200;
		}
	}
}

Where it reaches the _x if statement, and then it executes the _y movement while the clip is at 200 and it moves the block down to 200 then stops there.

it worked :slight_smile: thanxs again man!

No problem man.

Hey lost. Do these onEnterFrame commands still fire even if the mc reaches its defined x and y coordinates? I assume they do. Would you put an if statement in the code to delete the enterframe command? I’ve heard that saves CPU work.

Well moving one clip like that isn’t very CPU intensive, but yes, you can delete an onEnterFrame, but that would involve an onEnterFrame, not on onClipEvent(enterFrame).

So in that case the code above would become…

this.onEnterFrame = function {
	speed = 5;
	this._x += speed;
	if (this._x>=200) {
		this._x = 200;
		this._y += speed;
		if (this._y>=200) {
			this._y = 200;
                                delete this.onEnterFrame
		}
	}
}

Well moving one clip like that isn’t very CPU intensive, but yes, you can delete an onEnterFrame, but that would involve an onEnterFrame, not on onClipEvent(enterFrame).

So in that case the code above would become…

this.onEnterFrame = function {
	speed = 5;
	this._x += speed;
	if (this._x>=200) {
		this._x = 200;
		this._y += speed;
		if (this._y>=200) {
			this._y = 200;
                        delete this.onEnterFrame
		}
	}
}

man , just learn some basic programming , and then go intro ActionScript

if you know some bit of programming, Action Script becomes a very intuitive envoirement… my advice :slight_smile:

People dont know that all the code lost gave us is AI
Iv’e been studying that code for a wile now and could make a cirxcle go around a whole course.
All you would need is that when a car hits it
store last cordinates and make it move a couple digits away.

Well its really good code

Yeah, I don’t remember the last time I have ever used a tween though. All my motion is AS…lol.

Well, until I make my flash site, then I will be sure to need tweens somewhere…lol.

Lostin Beta

I tried many times to see if i can get the Circle tomove in a circle course.

Doesent seem to work

The cod eyou gave me is the only part thast wokrs.
Here is th code i have dont work right.

onClipEvent (enterFrame) {
    speed = 15;
    this._x += speed;
    if (this._x>=200) {
        this._x = 200;
        this._y += speed;
        if (this._y>=200) {
            this._y = 200;
            this._x -= speed;
            if (this._x>=200) {
                this._x = 200;
                this._x -= speed;
                if (this._x>=200) {
                    this._x = 200;
                    this._y += speed;
                    if (this._y>=200) {
                        this._x += speed;
                        if (this._x>=450) {
                            this._x = 450;
                        }
                    }
                }
            }
        }
    }
}

I hope you can help.

omg thats some insane nesting

HOLY SHIZMATS!!!

Yeah, that is definitely some insane stuff there…lol.

why arent you using the geometric formula for a circle to define the path - in place of the nesting nightmare you’ve created?:wink:

Peace