Flash metering and ambient light metering are done separately. Ambient metering is done before the shot, when you half press the shutter release button. Flash metering can be done in different ways; modern systems may use a pre-flash which fires just before the exposure, is read by the camera, which then tells the flash how much power to use for the actual exposure.
The flash metering may also work differently, depending on what mode you are shooting in. For example, if you are shooting in Auto or P mode, the flash will try to act as the main source of light for the exposure.
If, however, you are in Av or Tv, camera & flash will expose for the ambient light and use the flash more as fill light.
There is a lot more to it, it can actually be quite complicated.
If you are using Canon...there is a great site/article which explains it in great detail...it's often called the 'EOS Flash Bible'...and it can be found HERE