Question regarding contentBounds error message

I wonder what can cause this error here:

level.lua ERROR: ?:0: attempt to index field ‘contentBounds’ (a nil value) on device: iPad

What kind of usage can cause an error message like this? I wonder because I’m not directly using any .xmin .xmax in the code.

Is this also possible to get by using something like object.width ?

assuming you need this for some touch event, my code goes something like this where I also use bounds, if it helps

local function touchevent(event) local target=event.target if event.phase=="began" then local bounds=target.contentBounds target.xMin=bounds.xMin target.xMax=bounds.xMax target.yMin=bounds.yMin target.yMax=bounds.yMax display.getCurrentStage():setFocus(target) target.isFocus=true -- event elseif target.isFocus==true then if event.phase=="moved" then if not (event.x\>=target.xMin and event.x\<=target.xMax and event.y\>=target.yMin and event.y\<=target.yMax) then display.getCurrentStage():setFocus(nil) target.isFocus=nil -- event end elseif event.phase=="cancelled" then display.getCurrentStage():setFocus(nil) target.isFocus=nil -- event elseif event.phase=="ended" then display.getCurrentStage():setFocus(nil) target.isFocus=nil -- event end end return true end

.contentBounds is a property of a display object. If it’s saying it can’t find it, it’s because the object is likely not a display object or no longer a display object. Look for someplace you’re passing what used to be a display object to an API function.

Rob

assuming you need this for some touch event, my code goes something like this where I also use bounds, if it helps

local function touchevent(event) local target=event.target if event.phase=="began" then local bounds=target.contentBounds target.xMin=bounds.xMin target.xMax=bounds.xMax target.yMin=bounds.yMin target.yMax=bounds.yMax display.getCurrentStage():setFocus(target) target.isFocus=true -- event elseif target.isFocus==true then if event.phase=="moved" then if not (event.x\>=target.xMin and event.x\<=target.xMax and event.y\>=target.yMin and event.y\<=target.yMax) then display.getCurrentStage():setFocus(nil) target.isFocus=nil -- event end elseif event.phase=="cancelled" then display.getCurrentStage():setFocus(nil) target.isFocus=nil -- event elseif event.phase=="ended" then display.getCurrentStage():setFocus(nil) target.isFocus=nil -- event end end return true end

.contentBounds is a property of a display object. If it’s saying it can’t find it, it’s because the object is likely not a display object or no longer a display object. Look for someplace you’re passing what used to be a display object to an API function.

Rob