Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random Events

Status
Not open for further replies.

GooeyHand

Technical User
Jun 25, 2002
17
CA
Hey everyone,
I've been trying to make some boxes fade in and out in certain points randomly. I've been lookin all over for an answer, but nothing for exactly what I need.
The way I am envisioning this, is to have a MC open numerously at once on random x and y points I have chosen. I know there are a lot of ways to make a random action, but I haven't found anything relative to this.
If anyone has any thoughts it would be greatly appreciated, I’m really stuck.

Thanks
 
Some confusion! If there chosen points, how can they be random at the same time? Regards,

oldman3.gif
 
algorithm

name the boxes box1, box2, etc make them mc's

use random to choose a number between 1 (say) and the number of boxes

set the visible property of the box selected at random to false
 
Add this to the first frame of the main timeline:

function makeBoxes() {
for ( i = 1; i <= 100; i++ ) {
duplicateMovieClip( box, &quot;box&quot; + i, i );
_root[&quot;box&quot; + i]._x = Math.random() * 550;
_root[&quot;box&quot; + i]._y = Math.random() * 400;
_root[&quot;box&quot; + i]._alpha = Math.random() * 100;
}
}

Place the box MC on the stage, and give it the instance name box. In the box's action, put this.

onClipEvent (load) {
_root.makeBoxes();
}

onClipEvent (enterFrame) {
if ( this._alpha >= 100 ) {
this._alpha = 0;
this._alpha += 5;
}
}
 
flashmax,
i gave your technique a try, but when i published it a window came up warning me the script was slowing things down too much. plus i was hoping to make the MC's show up over images i already have on the scene. so the pigeon holes would have to be over exact x and y coordinates. thanks for the help.
 
Doesn't run slow on mine. You don't have to duplicate the movie clip 100 times though. That was basically just a suggestion.

If you want to create something that has specific x and y coordinates you need to use attachMovie(). You would set up something like:
function makeBoxes() {
attachMovie( box, box1, 3);
_root.box1._x = (whatever you want it to be);
_root.box1._y = (whatever you want it to be);
}

Do this for however many boxes you want, unless you are creating numerous boxes, in which, you can create a for loop that will do this nicely.

Use the onClipEvent's that I described earlier.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top