Moving symbols

Umm… beginner question maybe, but I’m just starting to pick up on this stuff…

I have two objects on my stage, one in a fixed position, and another object moving randomly. I want to have the object that’s moving randomly stop and move towards the stationary object whenever a certain action is performed. I might be using the word “object” instead of “symbol”, but I hope whoever reads this gets an idea of what I’m asking. The problem is clearly that the location of the random moving object can be anywhere, and I’m not sure how to move it to a certain co-ordinate (of the stationary object).

If this was some other language, I would figure out the x-y ratio between the two objects and have the random object move along that path until it reaches the other object. I’m sure there’s a much simpler way of doing this in flash.

Thanks.

Hi,
You migt like to give this a try;

First create a variable on your _root timeline, for example

[AS] var actionDone[/AS]

then in your random movement mc ( or wherever the code is)

[AS] if(_root.actionDone != 1){
//randome movement code here
}else{
//code to move the mc to
//stationary mc here
}[/AS]
Then when the action is performed make sure the var is increased to 1 and your mc should move accordingly from wherever it may ( randomly) be.

Hope that helps

SteveD

What I need is the

    //code to move the mc to
    //stationary mc here

:slight_smile:

like, is there a symbol.move(x,y) ?

I told you it was a beginner question.

no, there’s no real shortcut.

Try something like this.

timeToGetThere = 5;//frames
distance_x = (clip._x-destination_x)/timeToGetThere;
distance_y = (clip._y-destination_y)/timeToGetThere;

function onEnterFrame() {
clip._x += distance_x;
clip._y+= distance_y;
if(clip._x==destination_x)
delete this.onEnterFrame;

}

if you want it to get there instantaneously its easier.
Clip._x=destination_x;
Clip._y=destination_y;

Kinda the ratio thing I was talking about, but more efficiently written than I ever would have written it.

Thanks.

Hi,
Well, its not exactly and newbie Q and ** could ** be quite a complex answer. I cannot post any code for you as i do not know what the constants are.
First I would recommend you look in the tutes and lab sections of this site for movement code and do a search of the forums for the same. You will not find exactly what you need, but you will find something you can adapt.
The simplest format would be to define the x, y pos of the static mc and move the random mc toward it
[AS]if(this._x>staticmc._x){
this._x–;
} [/AS]
the same for the y pos

This assumes that your static mc is on the left hand side of the stage - it becomes far more complex if ( for example) your static mc is centre stage and the random mc is moving around it.
Once you have the basic movement down, you then need to decide how it will move, jump to the static mc ?, slide with easing ?,and so on.
If, after searching you cannot get the result you want, post your fla so that people can see where you are at.

Cheers
SteveD

Nice one clownstaples - now why didn’t I think of that instead of writing all that blurb !
SteveD