When I am in the company of someone I really enjoy being around then I am naturally flirty, whether it's a girl or guy. I can also be very flirty online when I am interacting with people that I enjoy talking with.
I still flirt with my husband all the time and he flirts with me. It's one of the things (out of many) that keeps the relationship fun and interesting imo.
I think in some instances, flirting can make a person seem more attractive. Let's use an example: A woman flirts with a man. He initially is not attracted to her, but as the flirting continues and time goes on, he starts to like the attention she is showing him. Her lighthearted, fun attitude appeals to his senses. Suddenly, she becomes more desirable. Liking the attention has made him like her and want to be around her more. He now considers her attractive.
But as you pointed out, not all flirting is about being sexually interested in the person or trying to get someone to be interested in you. I think it's more about friendly chemistry.