Hey,
I dont know if someone did this before or not or if this can be done with one of those nifty physics engines, but i havent seen it around so i thought i might aswell give it a go.
original: http://www.flight404.com/processing/magnets_2D/
port to as3: http://flinkmedia.net/projects/magnets2d/
source files as3: http://flinkmedia.net/downloads/magnets2d.zip
Yannick