Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Question regarding contentBounds error message
Started by d.mach Mar 18 2019 02:05 AM

- - - - -
2 replies to this topic
contentbounds
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 855 posts
  • Corona SDK

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 ?



[TOPIC: post.html]
#2

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 770 posts
  • Corona SDK

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


[TOPIC: post.html]
#3

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,904 posts
  • Enterprise

.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




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: contentbounds