The principle is similar to the system used to generate 30 kV for the ignition systems on petrol engines, or in the "Joule Thief" circuit.
An oscillator turns the current on and off, and this current is fed into a transformer, which increases the voltage. In many cases the oscillator is combined with the transformer and it won't oscillate without it. Transformers will not work on direct current, and batteries only produce direct current, so that is why the oscillator is needed.
In the fly swatter and camera flashes, the transformer output charges a capacitor and many thousands of oscillations are needed to build up enough charge for the item to work.