when a girl tells you she has a boyfriend she's not necesarily rejecting you. sometimes its true but girls also use that as a s-hit test. they want to see how you react. if you get pissed or immediately and eject, she just weeded out all the weak guys. next time it happens, stay calm, try not to show any reaction at all. deflect her comment by ignoring it and changing the subject. you can also make a funny comment like, "you're silly, so what i was saying was..."
as far as girls flaking it generally means you did not build enough attraction, and she gave you her phone # so you would stop talking to her and go away. a couple of things you can do to limit girls flaking on you is first and foremost work on your attraction game. the more attraction you build your flake rate will lower about 75%. the second thing you can do is have a specific event in mind to invite her too before you ever ask for the number. build up the event, then get her number. saying to a girl "we should hang out sometime whats your number" is boring and every other guy says that. there's no reason for her to answer or return your voicemail or text.