Why won't my function work?

hi

why won’t my below script work?

the movie clip is called “blue”

and i want it to move useing a function in a function
is it posible?

blue.onEnterFrame = function() {
movestop(this._x, 10, 500);

// movestop function

function movestop(thing, speed, dist) {
	thing += speed;
}

};

if i go

blue.onEnterFrame = function() {
this._x+=10;
}

then it works

thanks

Andrew

when you pass this._x in a function, it passes the value of this._x, not the property itself. Its like putting this._x in a textField. You get what _x is, whether it be 0 or 100 or 20 or whatever. Because of that, saying thing += speed; is like saying (whatever the numeric value of this._x was) += speed. Where, actually, you are just reassigning the variable thing and not affecting _x at all.

Now, the basic way to get around this is just to pass in the movieclip and specifically say _x within the function itself:

// define function
function movestop(thing, speed, dist) {
thing._x += speed;
};
// define onEnterFrame
blue.onEnterFrame = function() {
movestop(this, 10, 500);
};

Then the movieclip itself is passed which allows you to reference its own _x property to do what you will. However, with this you would need to have a seperate function for _y if you wanted to do something similar with that. But, alternatively, you could also use:

// define function
function movestop(thing, prop, speed, dist) {
thing[prop] += speed;
};
// define onEnterFrame
blue.onEnterFrame = function() {
movestop(this, "_x", 10, 500);
};

Which allows you to specify what property you want to change using another parameter in your function. That can be “_x” or “_y” or technically anything you want such as “_xscale” or “_yscale” as well. It does so using associative array referencing - you can find more about that here:
http://www.kirupaforum.com/forums/showthread.php?s=&threadid=12082

And don’t crospost, andrew :trout:

sorry did not mean to cross post
i will not do it again.

If i have a flash mx script question where should i put it

thanks

Andrew