Image Z order, Groups, and Director

Hello all, i have two questions regarding problems i ran into with Director class recently

  1. is there anyway to make sure img2 is above img1?
    [lua]localGroup = { display.newGroup(), display.newGroup() }

local img1 = display.newImage(“one.png”)
local img2 = display.newImage(“two.png”)

new = function()
localGroup[1]:insert( img1 )
localGroup[2]:insert( img2 ) – img2 should be ontop of img1, but this output display img2 below img1

return localGroup[2]
end[/lua]

  1. The “*” part (line 19) in the below code is where i don’t understand. Assuming i press the button and the image now is “two.png”, and then i press another button to change scene (not in code), “two.png” will still be removed. Can anyone explain how director class is able to remove that picture?
    [lua]localGroup = display.newGroup()

local newImg = display.newImage

local img_t = { “one.png”, “two.png”, “three.png” }
local img = newImg(img_t[1])

– This function will basically remove current image, and create the next on img_table
local count = 1
local function changeImg( event )
if count < #img_t then
count = count + 1
else
count = 1
end

img:removeSelf()
img = newImg(img_t[count])
localGroup:insert(img) – *
localGroup:insert(btn) – Making sure button ontop of new image
end

btn = ui.newButton{ default = “btn.png”, over = “btno.png”, onRelease = changeImg }

new = function()
localGroup:insert(img)
localGroup:insert(btn)

return localGroup
end[/lua]

Thank you for your time. [import]uid: 74723 topic_id: 12774 reply_id: 312774[/import]