Drag objects within limits

Hello everybody,
I have a page of my app where an object is draggable, but with the basic drag functions found in the Corona examples the user can move the object wherever he wants, even outside the screen, is it possible to set a limit in space (without using collisions) ? It would be great to set a virtual ‘box’ inside which the object can move.
I’m using the code from the ‘DragMe’ sample code

Thank you

Ray [import]uid: 106680 topic_id: 20046 reply_id: 320046[/import]

Create an enterFrame function and check the x/y values of the object. If the x/y values are higher than you want them to be then set the objects x/y to the max

local function limit()  
 local x = object.x  
 local y = object.y  
  
 if(x \> 100) then  
 object.x = 100  
 elseif(x \< 50) then  
 object.x = 50  
 end  
  
 if(y \> 100) then  
 object.y = 100  
 elseif(y \< 50) then  
 object.y = 50  
 end  
  
end  
Runtime:addEventListener("enterFrame", limit)  

This would make the draggable area for the object a square between x: 50-100 and y: 50-100 [import]uid: 14018 topic_id: 20046 reply_id: 78285[/import]

It works perfectly, thank you !

Ray [import]uid: 106680 topic_id: 20046 reply_id: 78399[/import]