Help me out with a game plz :)

im semi new to action script and i have no clue about collision detection i been look in websites for about 6 hrs now and found nothing to help
ok here is my dude. the trolly that hes on moves up and down i got that. but it keeps going what code would i use to stop him from hitting his head on the tree branch and also the ground again?
ne 1 know a site or some code that would help?