Draw and Clear Line

I have a simple function that I thought would allow me to draw a line and then allow me to move the touch position to move one end of the line.

However I seem to get lots of lines on the screen as the remove does not appear to be working, any help would be appreciated.

local function onBack( event )
if ( myLine ) then
myLine.parent:remove( myLine ) – erase previous line, if any
end
myline = display.newLine( 50,50, event.x,event.y )
myline:setColor( 255, 0, 0 )
myline.width = 3
end [import]uid: 7830 topic_id: 7090 reply_id: 307090[/import]

I had a similar problem. What worked for me was to separate the line removal code into its own function outside the event, then call it from within the event before drawing the new line. You have to declare the line object variable prior to and outside both functions as well. [import]uid: 9422 topic_id: 7090 reply_id: 25006[/import]