Finding nearest point of the outside of two objects

Hi all,
I have an interesting maths problem that is keeping me awake at night.
picture this:


                  .......___                           .........................................|

…/.2…\ …___…|
…|…| …/… \ …|
…_/…|…3…| …|
…|…|…|
…_
/…|
…|
…|
…|

two balls are stationary on stage and I am dragging ball 1 between them. I want my program to deny the ability to do this (technical terms) and move the ball automatically to the closest point available that does not overlap either of the other two balls i.e. the left side of the dragged ball may touch but not over lap ball 3. I have a feeling the circular equation: (x-a)^2 + (Y-b)^2 = c comes into it but it may need pythagoras instead as the balls are all circular but not all the same size. The best way I can see for this is to write a multi-part equation for the bounds of boths balls and then finding the nearest point, but not sure how to do this in as3, perhaps using the ‘for each’ tag…Any maths/programming help appreciated.