When I first started saving up kitchen compost, the container I was using was too small. The next container I tried attracted flies. I found this lovely container called the Max Air Composting Bucket which you line with biodegradable bags. I was assured that flies would not be an issue. They could not have been more wrong; we had fruit flies in every room of our house within a few weeks. I gave up composting completely while we worked on that issue!
Then I started keeping the compost bucket in the freezer and problem solved!