Flash pencil tool using actionscript

Hi, I need help with smoothing of lines. I have a application wherein the user can draw lines in any form. Most of the lines drawn aren’t smooth enough and in some instances the lines are very much zagged.

I happened to check similar functionality in the flash IDE, lines when drawn using pencil tool is zagged when the mouse is released the line smoothens. I would like to create the same smoothing functionality after the line is drawn using actionscript drawing API. Is there any algorithm or techniques using which I can acheive it.