Thanks for other quick reply @primoz. Ok, now i understand. I went through and removed the references to self as you earlier recommended, and added the code back into the proxy, and it now appears to be working as intended.
Heres my code for scrutiny or to help others
[lua]
–
– proxy.lua
– Adds “propertyUpdate” events to any Corona display object.
– Modified with _class and _proxy to fix display group references
local Proxy = { }
function Proxy.get_proxy_for( object )
– Metatables start from blank, or near blank tables
local proxy = { }
proxy.raw = object
– Use this to fix built-in corona functions
proxy._class = object._class
proxy._proxy = object._proxy
– Define metatable
local metatable = {
– table[key] is accessed
__index = function ( t, key )
– used to check specific errors in access
--print ( “Access”, t, key ) – debug comment
– This code allows raw passthrough for unproxied object
if key == “raw” then
return rawget( proxy, “raw” )
end
– pass method and property requests to the display object
if type(object[key]) == ‘function’ then
return function(…) arg[1] = object; objectkey end
else
return object[key]
end
– return object[key]
end,
– value written to table[key]
__newindex = function ( t, key, value )
– used to check specific errors in access
--print ( “Write”, t, key, value ) – debug comment
local event =
{
name = “propertyUpdate”,
target=t,
key=key,
value=value
}
object:dispatchEvent( event )
– update the property on the display object
object[key] = value
end
}
– Set metatable and return proxy
setmetatable ( proxy, metatable )
return proxy
end
return Proxy
[/lua]
and usage example. I hope this helps. Let me know if I have made any errors, or if theres better ways.
[lua]
Object = {}
function Object.new(params)
local object = display.newGroup()
– object properties to listen for
object.property = 0
– etc
– Setup Proxy and Listener
object = proxy.get_proxy_for( object )
function object:propertyUpdate( event )
– listen to updates on .property
if event.key == “property” then
print( "Changed " … event.key … " to " … event.value )
end
end
object:addEventListener( “propertyUpdate” )
– object functions below here
function object:exampleIncrement()
– body
object.property = object.property + 1
end
– etc
return object
end
return Object
[/lua]