How can I make this calculation in actionscript 3.0


I have a question that honestly I cannot figure out without any help. What I want to create is a calculator, which is going to calculate how many times “B” can fit into object “A” and as you can see in the illustration “B” is my variable and it can be any thing where on the other hand “A” will have a fixed dimension, in this case 4”x2”. I also would like to have a gap in between each object “B” (.100” x and y axis), this will also have a button to generate all the “B” objects and to show the total number of objects in object “A”. As you have noticed I don’t want to count incomplete objects.

I know I know I probably asked for something that can be very time consuming, but like I said I cannot do it without help.

Here is the link to the illustration of what I want:

Any help will be appreciated.

Thanks a lot,