Here, I wrote you a little sample that does this kind of thing.
The scripts are all in frame 1. It assumes the existence of a button named button_mc and a library movie with an export symbol called beastie_mc (the little critters).
This is the code:
Code:
// The number of critters you want
_root.maxBeasties = 100;
// An invisible MC to hold them - sits underneath your button
beastieFld = _root.createEmptyMovieClip("beastFld", 10);
// This puts your button on top of all the critters
// the only reason we need beastieFld is so we can accomplish that easily - otherwise i'd just use _root.
beastieFld.swapDepths(button_mc);
// Roll over script for your button
button_mc.onRollOver = function()
{
for (var i = 0; i < _root.maxBeasties; ++i)
{
var mc = beastieFld["bmc"+i];
if (mc == undefined)
{
mc = beastieFld.attachMovie("beastie_mc", "bmc"+i, i+1);
// mc._x = this._x;
mc._y = this._y;
mc.speed = 5 + random(5);
mc.onEnterFrame = function ()
{
var dx = (this.tx - this._x);
var dy = (this.ty - this._y);
this._x += dx/this.speed;
this._y += dy/this.speed;
if (dx < 5 && dy < 5) {
if (this.closing) {
this.removeMovieClip();
}
else {
this.tx = random(Stage.width);
this.ty = random(Stage.height);
}
}
}
}
mc.closing = false;
mc._xscale = mc._yscale = 30;
mc.tx = random(Stage.width);
mc.ty = random(Stage.height);
}
}
// Roll out script for your button
button_mc.onRollOut = function()
{
for (var i = 0; i < _root.maxBeasties; ++i) {
var mc = beastieFld["bmc"+i];
if (mc != undefined) {
mc.closing = true;
mc.tx = this._x;
mc.ty = this._y;
mc.speed = 5;
}
}
}
The hard part with this kind of thing (aside from being able to do it at all) is controlling the movement - constraining it to the area of interest, and making the motion look the way you want.
For each critter, the variables this.tx and this.ty control where he's gonna go. I currently have them programmed to go all over the entire field.
- jbum