# Controlling Random motion

**URL:** <https://forum.kirupa.com/t/controlling-random-motion/181366>\
**Category:** Uncategorized\
**Created:** [March 8, 2006, 5:42pm UTC](https://forum.kirupa.com/t/controlling-random-motion/181366 "2006-03-08T17:42:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kmokwete](https://avatars.discourse-cdn.com/v4/letter/k/e0b2c6/32.png) [@kmokwete](https://forum.kirupa.com/u/kmokwete)\
**Post date:** [March 8, 2006, 5:42pm UTC](https://forum.kirupa.com/t/controlling-random-motion/181366/1 "2006-03-08T17:42:17Z")

</div>

Hi  
I am a new born to Flash and I am really wishing somone would help me make my insatallation a reality.  
In short I want to adapt a script which generates random motion of two linked objects so that instead of the motion being RANDOM, I can feed an array of x an y cordinates of points to generate the movement.

The script is like this (courtesy of: Joshua Davies)

[COLOR=Blue]// init random jumping  
randomMove = 50;[/COLOR]

// start a variable to count our duplicated movie clips  
lineNum = 1;

this.onEnterFrame = function() {

[COLOR=Blue] // init Xpos movements  
newXpos = this.\_x+(random(randomMove)-(randomMove/2));  
curXpos = this.\_x;  
if (curXpos\<=\_root.boundLeft) {  
newXpos += random(randomMove);  
} else {  
if (curXpos\>=\_root.boundRight) {  
newXpos += -(random(randomMove));  
}  
}[/COLOR]

```
// init Ypos movements
newYpos = this._y+(random(randomMove)-(randomMove/2));
curYpos = this._y;
if (curYpos&lt;=_root.boundTop) {
    newYpos += random(randomMove);
} else {
    if (curYpos&gt;=_root.boundBottom) {
        newYpos += -(random(randomMove));
    }
}

// execute movement
this._x = newXpos;
this._y = newYpos;

// scale line between redDot and greenDot

_parent.line_mc.duplicateMovieClip ("newLine_mc" + lineNum, lineNum);

_parent["newLine_mc" + lineNum]._x = this._x;
_parent["newLine_mc" + lineNum]._y = this._y;

_parent["newLine_mc" + lineNum]._xscale = _parent.greenDot_mc._x-this._x;
_parent["newLine_mc" + lineNum]._yscale = _parent.greenDot_mc._y-this._y;

lineNum++;

```

};

A full animation is here:(chapter 20d)  
[http://www.flashtothecore.praystation.com/](http://www.flashtothecore.praystation.com/) (chapter 20d)

Now Instead of a random movement, I would like to feed in an array that would make the movement. I guess I am supposed to be changing the blue highlighted parts of the script…? I would be really happy for some help.

Thanks

K.
