# Random speed (or equivilent)

**URL:** <https://forum.kirupa.com/t/random-speed-or-equivilent/2678>\
**Category:** flash\
**Created:** [May 9, 2002, 4:04pm UTC](https://forum.kirupa.com/t/random-speed-or-equivilent/2678 "2002-05-09T16:04:56Z")\
**Posts on this page:** 7\
**Page:** 1

<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:** [May 9, 2002, 4:04pm UTC](https://forum.kirupa.com/t/random-speed-or-equivilent/2678/1 "2002-05-09T16:04:56Z")

</div>

Ok, I am working on this piece of flash:

[ffc.kickassgamers.com/mes…scape.html](http://ffc.kickassgamers.com/messiah/cityscape.html)

now, what I want to do is have cars going along the roads at random speeds, or just travelling along the roads in random orders, whichever… anyways, as you can see, I am going to have a menu on the left hand side, which targets text into the scroll box on the right, and I want that to be able to happen without the movie re-starting everytime the cars finish going round, so the cars are going round and round in the background, and the layer on top is static. Will that happen automatically or not?

Basically i need to know how to do random speed or random intervals, and then the layer thing, if someone could lend a hand please 😃

Thanks, Pez.

---

<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:** [May 10, 2002, 10:13pm UTC](https://forum.kirupa.com/t/random-speed-or-equivilent/2678/2 "2002-05-10T22:13:00Z")

</div>

Well, I HAD typed out the entire script to show you, but the textbox cleared out when I had pressed the back button. How lovely. I’ll repost the code later. I love EZBoard. Must remember to copy everything to clipboard before I preview. :mad:

---

<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:** [May 11, 2002, 5:15am UTC](https://forum.kirupa.com/t/random-speed-or-equivilent/2678/3 "2002-05-11T05:15:32Z")

</div>

Ok, thanks for when you get it done 🙂

---

<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:** [May 11, 2002, 1:17pm UTC](https://forum.kirupa.com/t/random-speed-or-equivilent/2678/4 "2002-05-11T13:17:17Z")

</div>

I got new hosting for my site…

[pezdemon.host.sk/index.html](http://pezdemon.host.sk/index.html)

=)

---

<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:** [May 11, 2002, 6:33pm UTC](https://forum.kirupa.com/t/random-speed-or-equivilent/2678/5 "2002-05-11T18:33:21Z")

</div>

pezdemon,

here’s a starting place for you.

make a movie of a car, export it from the library as “car”, and delete it from the stage. then put this code in frame 1, it should only run once:

```auto
 
function makeCar(){
&nbsp &nbsp &nbsp &nbsp var mc = _root.attachMovie("car","car"+_root.count,_root.count);
&nbsp &nbsp &nbsp &nbsp mc.reset();
&nbsp &nbsp &nbsp &nbsp mc.onEnterFrame = mc.drive;
}

MovieClip.prototype.reset = function(){
&nbsp &nbsp &nbsp &nbsp this._x = 100;
&nbsp &nbsp &nbsp &nbsp this._y = random(100);
&nbsp &nbsp &nbsp &nbsp this.spd = random(18)+12;
&nbsp &nbsp &nbsp &nbsp this.limit = 300;
}

MovieClip.prototype.drive = function(){
&nbsp &nbsp &nbsp &nbsp if(this._x > this.limit) this.reset();
&nbsp &nbsp &nbsp &nbsp else this._x += this.spd;
}

count = 5;
while(count--){
&nbsp &nbsp &nbsp &nbsp makeCar();
}

```

the reset method is where you have most of your control. the \_x is where the cars will start from, the limit is where they’ll go to before they reset, the \_y defines a range possible vertical placement, the spd defines a range of possible speeds.

count is how many cars.

---

<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:** [May 11, 2002, 6:43pm UTC](https://forum.kirupa.com/t/random-speed-or-equivilent/2678/6 "2002-05-11T18:43:40Z")

</div>

hmm, i notice on your site that you might want your cars to travel along a diagonal.

the script above could still be used as a starting place, but you’ll need some trig to get the diagonal thing happening. you might look at the random motion post and combine these scripts.

actually, it could be very similiar to the random motion, just with a fixed starting and ending point. or maybe choosing randomly from a series of fixed departure/destination pairs.

even more clever would be to have the cars turn at intersections.

good luck!

---

<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:** [May 11, 2002, 6:45pm UTC](https://forum.kirupa.com/t/random-speed-or-equivilent/2678/7 "2002-05-11T18:45:46Z")

</div>

I will have a look and play with it, I am really desperate to get it to work 😃 I have all of tomorrow to play, so wish me luck!
