Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

very weird problem with a button
Started by filippo66627 Jan 28 2020 07:04 AM

4 replies to this topic

Best Answer cyberparkstudios , 28 January 2020 - 07:17 AM

the quick fix is to move the 'function' block above both the button creations.  Scope issue - the first button is defined above the actual function so that button does not know the function exists.

local function handleButtonEventmtomm ( event )
local phase = event.phase 
if "ended" == event.phase then 
  print (99)
end 
end 
 
 
 local buttonmtomm = widget.newButton
{ left = 50,
  top = -10,
  width = 63,
  height = 30,
  defaultFile = ("Sfondi/icons/m to mm.png"),
  overFile = ("Sfondi/icons/m to mm.png"),
  onEvent = handleButtonEventmtomm
}
 
local buttontest= widget.newButton
{ left = 150,
  top = -10,
  width = 63,
  height = 30,
  defaultFile = ("Sfondi/icons/9.png"),
  overFile = ("Sfondi/icons/9.png"),
  onEvent = handleButtonEventmtomm
}

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

filippo66627

[GLOBAL: userInfoPane.html]
filippo66627
  • Enthusiast

  • 66 posts
  • Corona SDK

hi guys i have a problem with a simple button. I created 2 differents button but they're basically identical (the only thing that changes is the defaultFile and the overFIle) and they're both connected to a function which should print 99 in the console, well just one of them works and they're basically the same button. 

 

 
local buttonmtomm = widget.newButton
{ left = 50,
  top = -10,
  width = 63,
  height = 30,
  defaultFile = ("Sfondi/icons/m to mm.png"),
  overFile = ("Sfondi/icons/m to mm.png"),
  onEvent = handleButtonEventmtomm
}
 
local function handleButtonEventmtomm ( event )
local phase = event.phase 
if "ended" == event.phase then 
  print (99)
end 
end 
 
 
local buttontest= widget.newButton
{ left = 150,
  top = -10,
  width = 63,
  height = 30,
  defaultFile = ("Sfondi/icons/9.png"),
  overFile = ("Sfondi/icons/9.png"),
  onEvent = handleButtonEventmtomm
}
   ty all 


[TOPIC: post.html]
#2

cyberparkstudios

[GLOBAL: userInfoPane.html]
cyberparkstudios
  • Contributor

  • 587 posts
  • Corona SDK

  Best Answer

the quick fix is to move the 'function' block above both the button creations.  Scope issue - the first button is defined above the actual function so that button does not know the function exists.

local function handleButtonEventmtomm ( event )
local phase = event.phase 
if "ended" == event.phase then 
  print (99)
end 
end 
 
 
 local buttonmtomm = widget.newButton
{ left = 50,
  top = -10,
  width = 63,
  height = 30,
  defaultFile = ("Sfondi/icons/m to mm.png"),
  overFile = ("Sfondi/icons/m to mm.png"),
  onEvent = handleButtonEventmtomm
}
 
local buttontest= widget.newButton
{ left = 150,
  top = -10,
  width = 63,
  height = 30,
  defaultFile = ("Sfondi/icons/9.png"),
  overFile = ("Sfondi/icons/9.png"),
  onEvent = handleButtonEventmtomm
}


[TOPIC: post.html]
#3

filippo66627

[GLOBAL: userInfoPane.html]
filippo66627
  • Enthusiast

  • 66 posts
  • Corona SDK

 

the quick fix is to move the 'function' block above both the button creations.  Scope issue - the first button is defined above the actual function so that button does not know the function exists.

local function handleButtonEventmtomm ( event )
local phase = event.phase 
if "ended" == event.phase then 
  print (99)
end 
end 
 
 
 local buttonmtomm = widget.newButton
{ left = 50,
  top = -10,
  width = 63,
  height = 30,
  defaultFile = ("Sfondi/icons/m to mm.png"),
  overFile = ("Sfondi/icons/m to mm.png"),
  onEvent = handleButtonEventmtomm
}
 
local buttontest= widget.newButton
{ left = 150,
  top = -10,
  width = 63,
  height = 30,
  defaultFile = ("Sfondi/icons/9.png"),
  overFile = ("Sfondi/icons/9.png"),
  onEvent = handleButtonEventmtomm
}

ty could i text u to ask about a problem when changing scenes ?



[TOPIC: post.html]
#4

cyberparkstudios

[GLOBAL: userInfoPane.html]
cyberparkstudios
  • Contributor

  • 587 posts
  • Corona SDK

yes.   cyberparkstudios@gmail.com. or you could use the private message here on the corona site

 



[TOPIC: post.html]
#5

filippo66627

[GLOBAL: userInfoPane.html]
filippo66627
  • Enthusiast

  • 66 posts
  • Corona SDK

yes.   cyberparkstudios@gmail.com. or you could use the private message here on the corona site

ty i've sent u an email




[topic_controls]
[/topic_controls]