how to set an new image to an existing display.newImageRect reference?

Let’s say I have this code:

 moon = display.newImageRect("moon.png", W/4, H/4)  
 moon:setReferencePoint(display.CenterReferencePoint)  
 moon.x = 200  
 moon.y = 100  

and later in the code logic I wish to change moon.png by newmoon.png. Can I use the existing moon reference and do something like:

 moon:setImage("newmoon.png") --???  

I read the API but didn’t find a way to set an new image to an existing display.newImageRect reference.
Thanks in advance for your help. [import]uid: 23471 topic_id: 8564 reply_id: 308564[/import]

[lua]local moon = display.newRect(0,0,100,100)
print(moon) – 02AAF6C0
moon:removeSelf()
print(moon) – 02AAF6C0, note *NOT* nil
moon = display.newCircle(0,0,100)
print(moon) – 02AAF788[/lua] [import]uid: 6645 topic_id: 8564 reply_id: 30798[/import]

or to clarify
[lua]local moon = display.newRect(0,0,100,100)
print(moon)
moon:removeSelf()
print(moon)
moon = display.newCircle(0,0,100)
print(moon)
local function printMoon()
print(moon) – NB, never *nil*
end

local function doRemoveAndPrint()
moon:removeSelf()
Runtime:addEventListener(“enterFrame”, printMoon)
end

moon:addEventListener(“tap”, doRemoveAndPrint)[/lua]

moon is not nil until you set it to [lua]moon=nil[/lua]. it’s still a reference to an empty table after calling [lua]:removeSelf[/lua] [import]uid: 6645 topic_id: 8564 reply_id: 30801[/import]

jmp909 - many thanks for your feedback.

In fact moon:removeSelf() is only half satisfactory because I would like to keep from my initial moon object the properties already set such as .x and .y…
When we use a display.newText object it is possible to change the text anytime with myText.text = … as shown in the example below:

local myText = display.newText("Hello", 0, 0, native.systemFont, 12)  
myText:setTextColor(255, 255, 255)  
myText.size = 16  
myText.text = "Hello World!"  

Somehow the “.text” property is public for the newText object, is there a similar “.image” property available for a newImageRect object? That’s what I’m looking for really :slight_smile: [import]uid: 23471 topic_id: 8564 reply_id: 30862[/import]

no.

but what about making moon a group and then adding and removing images from that? [import]uid: 6645 topic_id: 8564 reply_id: 30885[/import]

Yes a goup will certainly help me as I was looking for a form of container for my image(s).
Many thanks for your responses. [import]uid: 23471 topic_id: 8564 reply_id: 31000[/import]