Halley, this is a difficult one to teach your children.
Obviously, they need to know that talking with strangers could be dangerous - but you don't want to curb their natural curiosity and their social development. I always told my three children that, regardless of what they saw on the tv, not every "baddie" is a man; women can be "bad" too. They were taught to be polite, even to strangers and their stock answer in a difficult situation would be "I'm sorry, my mummy says I mustn't speak to people I don't know" and to turn away and walk swiftly but calmly away from that person.
A really difficult subject, as the majority of the world is full of harmless, lovely people but it's the minority we have to guard against. Tell them to use their instincts; if they don't like the look of someone, or the way they talk/act, then get out of the situation quickly.