You need to make sure your flash unit can keep up with your camera shutter speed.
I'm not sure about the specifics, but I think HSS (High Speed Sync) will allow you to avoid those situations. But your flash needs to support it.
If not, just manually change your shutter speed to what the flash permits.