PDA

View Full Version : change direction via script


sandman9
03-13-2003, 06:40 PM
I have done a search but did not find anything so here goes ....... I have the following script on my MC:

onClipEvent (load) {
_root.p_topT = 122;
}
onClipEvent (enterFrame) {
cY = this._y;
difY = cY-_root.p_topT;
setProperty(this, _y, cY-(difY/2));
}

This moves my MC to position 122 (p_topT is the instance name of my MC). Does anyone know what script I could use to make this MC go to a different location once it has reached 122?

I try'd playing around with a if (p_topT==122) ...... but had no luck

jaybee
03-13-2003, 07:54 PM
If you are using mx you could do something like:


function gotoYPos() {
difY = this._y-this.p_topT;
(Math.abs(difY)<.1) ? this.onEnterFrame = undefined : this._y = cY-(difY/2);
}

function setDir(clip,yPos) {
clip.p_topT = yPos;
clip.onEnterFrame = gotoYPos;
}

setDir(my_mc, 122);



then you can call setDir() with a new yPos whenever you like - on a button click/user event or when you reach the target...

sandman9
03-13-2003, 09:16 PM
Jaybee

I don't follow :(

jaybee
03-14-2003, 08:36 AM
I was just trying to say if you put it in a function then you can always call it again with a different value. noticed an error in there though, change the first function to this:


function gotoYPos() {
difY = this._y-this.p_topT;
(Math.abs(difY)<.1) ? this.onEnterFrame = undefined : this._y -= difY/2;
}

sandman9
03-14-2003, 06:29 PM
Do I put that on a OnClipEvent (load) or (enterframe) ...........

PS-could you attach a simple fla file?

Thank you for the help
Sandman9

jaybee
03-14-2003, 06:49 PM
here's a fla - this has two buttons each of which send a target mc to a diff y position....if you wanted to automatically move from one point to the next you would have to use arrays....

jaybee
03-14-2003, 06:51 PM
& bear in mind that this is mx code - it's nothing you can't do in f5 but it would just need organising differently.

sandman9
03-14-2003, 08:24 PM
ohhhhh i think I understand the confusion now. The code I put above will move the object on enterframe ...... so what I was asking was for it to move again once it reached it's destination ....... your code will move the object on the click of a button

sandman9
03-14-2003, 08:27 PM
here, check out this example. You will see that when you test the movie it will send the MC on stage, to location 350. What i need it to do is go to 350 like it does but then go elswhere once it reaches 350 (say maybe go to like 100 after it's gone to 350)

sandman9
03-14-2003, 08:28 PM
oppps here it is

jaybee
03-15-2003, 12:05 PM
here you go - this uses the same code in my first fla, but if you call the function with a list or targets like setDir(my_mc, 122, 350, 0, 200) it will make them into an array and go to one after the other:


function gotoYPos() {
difY = this._y-this.p_topT;
if (Math.abs(difY)<.1) {
if (this.targs.length) {
this.p_topT = this.targs[this.targCount++];
} else {
delete this.targs;
this.onEnterFrame = undefined;
}
} else {
this._y -= (difY/2);
}
}
function setDir(clip) {
clip.p_topT = arguments[1];
if(arguments.length >2) {
clip.targs = new Array();
clip.targCount = 0;
for(var i=2;i<arguments.length;i++) clip.targs.push(arguments[i]);
}
clip.onEnterFrame = gotoYPos;
}

btn1_btn.onRelease = function() {
setDir(my_mc, 122, 350, 0, 200);
}
btn2_btn.onRelease = function() {
setDir(my_mc, 500);
}

sandman9
03-15-2003, 05:33 PM
in the following code:

btn1_btn.onRelease = function() {
setDir(my_mc, 122, 350, 0, 200);
}

Are those 4 locations? if so then why does it only go to two differ locations (like it goes to one location and then goes to one more places after that)

Lastly what can I change "btn1_btn.onRelease = function()" ... to so that it will execute this command without a click of the button .....

thank you
Sandman9

jaybee
03-17-2003, 08:42 PM
in the fla I posted it was going to however many positions you put in, I think.....

to execute the code without a button, just put


setDir(my_mc, 122, 350, 0, 200);


on a frame somewhere on the main timeline.,