Compass ?

I’m creating an app with a lot of scenes created using the director class. 

In some scenes there is a compass: at first it works, but when I exit the scene and then enter again, the compass doesn’t work anymore. 

[lua]-- [Pointer]

local pointerS = display.newImageRect(‘compass_SHADE@4x.png’, 80, 80)
pointerS.x = 161
pointerS.y = 431
localGroup:insert(pointerS)

local pointer = display.newImageRect(‘compass@4x.png’, 80, 80)
pointer.x = 160
pointer.y = 455
localGroup:insert(pointer)

– Heading Text

local heading = display.newText(‘0’, display.contentCenterX, 60, native.systemFont, 21)
localGroup:insert(heading)
– Functions

local update = {}

– Main Function

function Main2()
pointer:setReferencePoint(display.CenterReferencePoint)
pointer.x = 160
pointer.y = 430

heading:setTextColor(255)
heading.x = 800
heading:setReferencePoint(display.CenterReferencePoint)

Runtime:addEventListener(‘heading’, update)
end

function update(e)
– Pointer Rotation

pointer.rotation = math.floor(e.magnetic)

– Heading Text & Direction

if(pointer.rotation >= 0 and pointer.rotation < 23) then
heading.text = math.floor(e.magnetic) … ’ N’
heading:setReferencePoint(display.CenterReferencePoint)
heading.x = 800
elseif(pointer.rotation >= 23 and pointer.rotation < 68) then
heading.text = math.floor(e.magnetic) … ’ NE’
heading:setReferencePoint(display.CenterReferencePoint)
heading.x = 800
elseif(pointer.rotation >= 68 and pointer.rotation < 113) then
heading.text = math.floor(e.magnetic) … ’ E’
heading:setReferencePoint(display.CenterReferencePoint)
heading.x = 800
elseif(pointer.rotation >= 113 and pointer.rotation < 158) then
heading.text = math.floor(e.magnetic) … ’ SE’
heading:setReferencePoint(display.CenterReferencePoint)
heading.x = 800
elseif(pointer.rotation >= 158 and pointer.rotation < 203) then
heading.text = math.floor(e.magnetic) … ’ S’
heading:setReferencePoint(display.CenterReferencePoint)
heading.x = 800
elseif(pointer.rotation >= 203 and pointer.rotation < 248) then
heading.text = math.floor(e.magnetic) … ’ SW’
heading:setReferencePoint(display.CenterReferencePoint)
heading.x = 800
elseif(pointer.rotation >= 248 and pointer.rotation < 293) then
heading.text = math.floor(e.magnetic) … ’ W’
heading:setReferencePoint(display.CenterReferencePoint)
heading.x = 800
elseif(pointer.rotation >= 293 and pointer.rotation < 360) then
heading.text = math.floor(e.magnetic) … ’ NW’
heading:setReferencePoint(display.CenterReferencePoint)
heading.x = 800
end
end

Main2()
[/lua]