Dynamic mask effect with actionscript like in photoshop

hi

i have seen how mask in photoshop works. however flash mask does not work like that.
i want to create a effect in flash with a image dynamically. probably involving bitmapdata. can some one guide me on this.
please see the pictures below to understand what i want.

as yo can see the second image is the actual one. i want to create the first one from the second one using actionscript. but the problem is flash masking does not nderstand gradient mask etc: what do i do ?