With flash, there are two exposures in effect. Aperture+shutter speed determine the amount of ambient light recorded, and Aperture + flash power (+ distance) determine the amount of flash recorded. Let's say you are shooting in a fairly dark area, like an interior. The ambient light exposure for that amount of light could be 1/30 sec at f/5.6. A flash with a guide number of 50 would need to be placed at 9 ft. from the subject to expose correctly at full power and f/5.6. The actual flash duration is very short, 1/5000 of a second or faster, and the only role for the camera shutter is to be open when the flash fires. But in this example, the common element is the aperture, being set to f/5.6. So the sequence of events is as follows:
1) you press the shutter button,
2) the camera closes the aperture down to the one chosen (in this case f/5.6),
3) the shutter opens to start the exposure
4) the camera sends a signal to the flash to fire (this assumes your camera is set for first-curtain sync).
5) the flash fires a very brief pulse of light, and its work is done.
6) the camera counts down the exposure (now it is only the ambient that is being recorded)
7) the camera shuts the shutter, and the exposure is complete.
If your camera was set up for second-curtain sync, the camera would fire off the flash just before the shutter would close.
For most flashes, there is a maximum shutter speed (usually around 1/200 sec) which is called the sync speed. This is the fastest shutter speed you can use on a particular camera with a single-fire flash. The reason this happens is that the shutter is actually made up of two curtains. The first curtain opens, some time elapses,then the second curtain closes. For speeds above 1/200 sec, the second curtain starts to close before the first curtain is fully open, creating a travelling slit which exposes the sensor. The faster the shutter speed, the thinner is the slit. Since the flash pulse is much faster than the shutter, shooting a flash with high shutter speed will result in black bands in the image, which are the shadows of the curtains travelling across the sensor. So the sync speed is the fastest speed at which the sensor is fully exposed (ie, first curtain is completely open, and the second curtain hasn't started closing).
Some flashes are designed to overcome this sync speed limitation by having a "high-speed sync" mode, in which the flash behaviour changes from a single pulse, to a series of smaller power pulses that fire over a longer period of time. Then, as the shutter slit moves across the sensor (at shutter speeds higher than the sync speed), the flash continues to fire very short pulses, that allow the sensor to become fully illuminated by the flash by the time the travelling slit closes.
Returning to the issue of flash vs. ambient. It is part of a photographer's bag of tricks to determine how much contribution he/she wants from each source. In the case of using a fill flash on a bright day, the camera exposure is set according to the ambient light. Let's assume we're shooting at ISO 100, and it's a bright sunny day. The sunny-16 rule applies, which says that you will have a proper exposure at 1/100 sec at f/16. You now have to tell the flash (assuming you're doing this manually) how much power to put out, and at what distance (because of the inverse square law that we discussed the other day). Again, assume you have a flash with guide number of 50. The flash needs to be about 3 ft. away from your subject to give a "proper" exposure at f/16. However, you don't want the light to be equal to the ambient, because you want it only to fill in the shadows. Fill is about 2-3 stops below the "normal" exposure. So let's say we want the light to be 2 stops less. A quick calculation tells me that the flash needs to be at 12.5 ft. to give me the right amount of light. Alternatively, I could reduce the flash power from full to 1/4 (2-stops) to get the right exposure. This will therefore give me a properly exposed ambient light photo, AND give me some fill in the shadows.
Alternatively, you may want the flash to be the main source of light, and the ambient exposure to be 2 stops less. This is known as "killing the sun". Assuming we are still working with a flash with a guide number of 50, you'd have to locate the flash about 8 inches from your subject to get that amount on light on the subject. This is not really ideal, so photographers use higher-powered flash units to locate the flash at a reasonable distance from the subject, and still provided enough light to overpower the sun.