Swarming flies

ok, i’ve just started learning AS3 so this isn’t as advanced or even nearly as useful as most stuff posted here.

Anyway, this is a class that creates a bunch of tiny flies that fly towards and swarms around a specified point. that point can be defined as a movieclip (the centerpoint of that movieclip) and the flies will then follow that movieclip if it moves.

here is the class:

http://home.graffiti.net/ct16/Flies.as

description:

call the script like this from a .fla:

ActionScript Code:
[FONT=Courier New][LEFT][COLOR=#000000]**var**[/COLOR] myFlies:Flies = [COLOR=#000000]**new**[/COLOR] Flies[COLOR=#000000]([/COLOR]n:[COLOR=#0000FF]int[/COLOR], mcFollow:[COLOR=#0000FF]MovieClip[/COLOR][COLOR=#000000])[/COLOR];

[/LEFT]
[/FONT]

“mcFollow” is a movieclip that the flies will follow. if no “mcFollow” is provided you can still access the position that the flies are attracted to by using _position like this:

ActionScript Code:
[FONT=Courier New][LEFT]myFlies._position.[COLOR=#000080]x[/COLOR] = [COLOR=#000080]100[/COLOR];

myFlies._position.[COLOR=#000080]y[/COLOR] = [COLOR=#000080]100[/COLOR];
[/LEFT]
[/FONT]

if a “mcFollow” was provided then changing _position will also change the position of “mcFollow”.

“n” is the amount of flies. default is 1. the amount of flies can also be set later with setAmount() like this:

ActionScript Code:
[FONT=Courier New][LEFT]myFlies.[COLOR=#000080]setAmount[/COLOR][COLOR=#000000]([/COLOR]n:[COLOR=#0000FF]int[/COLOR][COLOR=#000000])[/COLOR];

[/LEFT]
[/FONT]

here’s an example with 100 flies following the cursor:

View example
http://home.graffiti.net/ct16/Flies_Test.html

i think the class is kinda poorly written and could be made more efficient and stuff, but… i don’t care, it works!