Thats some good thinking.
I don't know how to do it personally, but check out the php/flash tutorials on this site. They can also lead you to other tutorials if you read the comments at the bottom by the readers.
Let me know if you find a good way to do this, because it would be very useful for me as well.