It could be a couple of things. When you were having your bad cramps, are breathing really hard or fast? Pain can cause us to do breath too hard/fast and basicly cause us to hyperventillate. When that happens, you can become very light headed and even black out. The more you breath hard/fast, the worse it will get. If you think that could be the problem, try keeping your breathing calm.
If that's not it, you could be losing too much blood during your period. If you are losing too much blood, that will also make you light headed and cause you to black out. If you think this might be the cause, then you should see your doctor as soon as possible. It could lead to serious problems.
Also, poor blood circulation can cause light headedness and blackouts. Again, see the doctor if it could be this.