You give no indication of stack sizes, and I'm a bit unclear about the positions of the players, but if you're both all in I can't see you did anything wrong.
If you were in exactly the same situation 3 times, on average your opponent would hit his flush once and win $x, and miss it twice when you'd win $x each time. Overall your play has positive Expected Value (+EV), which means you'll show a profit with it in the long term.
This particular hand was the one time out of three that you lose.