Seed a random number

My FLASH movie repeats the last 100 frames indefinitely (the end of the move does a goToAndPlay() to repeat them). in these frames, i go to place an object at a random location. the first time it loads the movie it loads a random location, but when these frames repeat, the object loads in the SAME location, not a random one.

my random number code for the object looks as follows:

onClipEvent (load) {
_x = random(300);
_y = random(300);
}

i even tried placing a random function in the timeline:

function randomNum() {
return Math.round(Math.random()*300+1);
}

and calling it in the object
onClipEvent (load) {
_x = _root.randomNum();
_y = _root.randomNum();
}

someone please help!!! (-:

technically, if an object is on a timeline, the onLoad (your onClipEvent (load)), will run only once, because it has been loaded already.

What you want to do is control it’s position from a frame, most likely the first frame. That way, you will definitely know those actions will be called.

//from first frame
obj._x = random(300); //of course, replace 'obj' with the name of the object
obj._y = random(300);

and that should move your MC everytime :thumb:

I don’t know if I’m not explaining myself correctly, or if I did not implement your code correctly, so I’ll try to explain again.

So my movie is 75 frames long. On the second frame, the movie executes the code:

[AS]starBright._x = random(300);
starBright._y = random(30);
starBright.play();[/AS]

So imagine the movie picks the random numbers 216 and 12. Instance starBright of star_alpha then plays at the random location (216,12). All is great so far.

At the end of the movie, the movie executes a [AS]goToFrame(2);[/AS]. Thus it loops back.

When the movie again gets to frame 2, the starBright movie plays again. However, it plays at the same location, in this example (216,12), instead of playing at a [COLOR=red]NEW, DIFFERENT RANDOM location[/COLOR]. lol.

Do I declare a new object in frame 2? Do I unload the movie in frame 75?

All suggestions welcome. Attached is the watered down movie if it helps at all.

Thanks

ok i can’t seem to simplify the movie enough to attach it. you can find it at www.tcnj.edu/~hoppe2/oeom/air-water.fla

use

Math.round(Math.random()*300)

in stead of

random(300)

and

gotoAndPlay(2)

in stead of

goToFrame(2)

this might be the problem…

You da man!!! GoToAndPlay() was the deciding factor

:blush: