Change object when dragged to a certain point?

I need something which can change a ball into a rectangle as it passes the halfway point of the screen…

So I’m gussing something like

if y < display.contentHeight/2

then removeSelf()

and change to rectangle? the rectangle will be another image file so it just needs to change to that…
Please help, I have no idea on how to code this!
Thank you! [import]uid: 24350 topic_id: 5460 reply_id: 305460[/import]

i’ve broken it up into small functions so you can see what each is doing

[lua]local obj
obj = display.newImage(“ball.png”)
obj.x = 100
obj.y = 100
local currentObjectType = “ball”
local function changeObjectTo(objType)
obj:removeSelf()
obj = display.newImage(objType…".png")
currentObjectType = objType
end
local function checkBall()
if(obj.y < display.contentHeight/2) then
changeObjectTo(“square”)
end
end
local function checkSquare()
if(obj.y < 0) then
obj.y=display.contentHeight()
changeObjectTo(“ball”)
end
end

local function moveObject()
obj.y=obj.y-1
end
local function checkObject()

if(currentObjectType == “ball”) then
checkBall()
elseif(currentObjectType==“square”) then
checkSquare()
end
end
local function onEnterFrame(event)

moveObject()
checkObject()

end

Runtime:addEventListener(“enterFrame”, onEnterFrame)[/lua] [import]uid: 6645 topic_id: 5460 reply_id: 18428[/import]

hmm sorry you wanted to drag it, didn’t you.

[import]uid: 6645 topic_id: 5460 reply_id: 18430[/import]

thanks! with a bit of editing and your code, I’ve got it to work. [import]uid: 24350 topic_id: 5460 reply_id: 18904[/import]