Dynamically cropping (masking) an image

Hi, I made an xml loaded dynamic image gallery and I cannot figure out how to crop the image should it be too big.
Masking appears to work only with a movieclip created outside of actionscript (which cannot be created dynamically).

Thanks in advance.