# Why won't my function work?

**URL:** <https://forum.kirupa.com/t/why-wont-my-function-work/25310>\
**Category:** Uncategorized\
**Created:** [July 11, 2003, 12:24pm UTC](https://forum.kirupa.com/t/why-wont-my-function-work/25310 "2003-07-11T12:24:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrew1234](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@andrew1234](https://forum.kirupa.com/u/andrew1234)\
**Post date:** [July 11, 2003, 12:24pm UTC](https://forum.kirupa.com/t/why-wont-my-function-work/25310/1 "2003-07-11T12:24:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 11, 2003, 2:11pm UTC](https://forum.kirupa.com/t/why-wont-my-function-work/25310/2 "2003-07-11T14:11:15Z")

</div>

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:

```auto
// 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:

```auto
// 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](http://www.kirupaforum.com/forums/showthread.php?s=&threadid=12082)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 11, 2003, 2:50pm UTC](https://forum.kirupa.com/t/why-wont-my-function-work/25310/3 "2003-07-11T14:50:11Z")

</div>

And don’t crospost, andrew :trout:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 11, 2003, 3:17pm UTC](https://forum.kirupa.com/t/why-wont-my-function-work/25310/4 "2003-07-11T15:17:48Z")

</div>

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
