Runtime error with corona app - runtime-error

I made a very simple app with a some simple functions and it is working very well on the corona simulator as in the Screen shot but when i built an APK file i got the following error when i opened the app on my phone "c:\Users\Moamen\Documents\Corona projects\Learning\main.lua:36:attempt to index global 'an'(a nil value) "
This is the app error:
Photo for the app on corona simulator:
and this is the Working folder
code:
-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------
-- Your code here
sound = audio.loadStream( "test2.mp3" )
ssound = audio.loadSound( "test.wav")
function com( )
audio.play( ssound )
audio.setVolume( .5)
--body
end
local options={duration = 10000 , onComplete = com }
audio.play( sound )
audio.setVolume( .25 )
group = display.newGroup()
function Puse( event)
if ("began" == event.phase) then
audio.pause()
end
-- body
end
function Resume( event)
if ("began" == event.phase) then
audio.resume( )
end
--body
end
--local widget = require("widget")
--widget.setTheme( "widget_theme_ios" )
an = display.newImage( "bg.JPG" ,150,250 )
an.xScale = .3
an.yScale = .7
--aa = display.newImageRect("bg2.JPG",100,100)
--aa.x=160
--aa.y=230
text1 =display.newText({text= "TechForm" , x=455 , y= 1 , fontSize=("60")})
transition.to( text1, {x=150,y=1,time =2000} )
text2=display.newText({text= "The android app that made by " , x=455 , y= 70 , fontSize=("20")})
transition.to( text2, {x=160,y=70,time =4000} )
text3=display.newText({text= "Moamen Hassaballah " , x=460 , y= 120 , fontSize=("30")})
transition.to( text3, {x=160,y=120,time =5000} )
--display.newImage("ando.png",160 ,350)
--display.newCircle( 300, 300, 10 )
rect = display.newRect( 170, 475, 400, 100 )
rect:setFillColor(.117,.244,.244)
ttext=display.newText({text="Thanks for using our app", x=150, y=470 ,fontSize=25} )
--rect:removeSelf( )
function Touching( event)
if ("began" == event.phase) then
x=math.random( .1,.9 )
y=math.random( .1,.9 )
z=math.random( .1,.9 )
rect:setFillColor( x,y,z )
end
end
rect2=display.newRect( 70, 387, 125, 23 )
rect:addEventListener( "touch", Touching )
button = display.newImage("button.png",60,334)
button.xScale=.4
button.yScale=.4
function ch_color( event)
if ("began" == event.phase) then
x=math.random( .1,.9 )
y=math.random( .1,.9 )
z=math.random( .1,.9 )
text3:setFillColor( x,y,z )
end
end
rect2:addEventListener( "touch", ch_color )
local widget = require("widget")
widget.setTheme( "widget_theme_ios" )
function login(event)
if ("began" == event.phase) then
rect:removeSelf( )
function login2( event)
if ("began" == event.phase) then
rect = display.newRect( 170, 475, 400, 100 )
rect:setFillColor(.117,.244,.244)
rect:addEventListener( "touch", Touching )
ttext:toFront( )
btn = widget.newButton{top=365,left=150 , label="Login" , onEvent=login}
btn.xScale=.8
btn.yScale=.7
end
-- body
end
btn = widget.newButton{top=365,left=150 , label="Login" , onEvent=login2}
btn.xScale=.8
btn.yScale=.7
end
-- body
end
local btn = widget.newButton{top=365,left=150 , label="Login" , onEvent=login}
btn.xScale=.8
btn.yScale=.7
local bb = widget.newButton{ label = "Puse" , top = 250 , left = 150 ,onEvent=Puse}
bb.xScale=.8
bb.yScale=.7
local bb2 = widget.newButton{ label = "Resume" , top = 250 , left = 2 ,onEvent=Resume }
bb2.xScale=.8
bb2.yScale=.7
function handleTabBarEvent(event)
if event.phase == "press" then
print ("Tab " .. event.target._id .. " is selected")
transition.to( cc, {x= -160 , y=220 , time=200} )
end
end
cc = display.newText( {text = "Shows Tap is selected" , x=-160 , y=220, fontSize = 30} )
function shows(event )
if (event.phase=="press") then
print( "shows tap is selected" )
transition.to( cc, {x= 160 , y=220 , time=400} )
end
-- body
end
-- Configure the tab buttons to appear within the bar
local progressView = widget.newProgressView
{
left = 10,
top = 320,
width = 300,
isAnimated = true
}
-- Set the progress to 50%
function progress_to_0(event)
if event.phase=="press"then
xx = math.random( 0.1 , 0.9 )
progressView:setProgress( 0.1 )
transition.to( cc, {x= -160 , y=220 , time=200} )
end
end
function progress_to_25(event)
if event.phase=="press"then
progressView:setProgress( 0.25 )
transition.to( cc, {x= -160 , y=220 , time=200} )
end
end
function progress_to_75(event)
if event.phase=="press"then
progressView:setProgress( 0.75 )
transition.to( cc, {x= -160 , y=220 , time=200} )
end
end
function progress_to_1(event)
if event.phase=="press"then
progressView:setProgress( 1 )
print( "shows tap is selected" )
transition.to( cc, {x= 160 , y=220 , time=400} )
end
end
local tabButtons = {
{
label = "Tab1", -- Text of the label
selected = true, -- Default selection
size = 16, -- size of the font in the Tab
onPress = progress_to_0 -- listener attached to the Tab
},
{
label = "Tab2", -- Text of the label
size = 16, -- size of the font in the Tab
onPress = progress_to_25 -- listener attached to the Tab
},
{
label = "Tab3", -- Text of the label
size = 16, -- size of the font in the Tab
onPress = progress_to_75
-- listener attached to the Tab
},{label="Shows" , size=16, onPress=progress_to_1 }
}
-- Create the Tabs object
local testTabs = widget.newTabBar
{
top = -45,
width = display.contentWidth,
height = 70,
buttons = tabButtons,
}

Android is case sensitive but Windows is (generally) case insensitive. So replace bg.JPG with bg.jpg and rename file accordingly.
Note:
Use small letters for file names,
Use local variables where possible e.g. local an = display.newImage( "bg.jpg" ,150,250 )

Related

Why do I get error "missing 1 required positional argument"?

Why I continue getting the error :
missing 1 required positional argument: 'category_id'
when the argument is already passed within query function in Backend class? I also don't understand the error of unfilled self or missing positional argument self:
missing 1 required positional argument: 'self'
I tried passing self to display_account_types() in Frontend class but it doesn't reflect. Do I need to pass self within the inner nested functions within a class?
import tkinter
from tkinter import *
from tkinter import ttk
import tkinter.messagebox
import sqlite3
root =Tk()
root.title('Simple Application')
root.config(bg='SlateGrey')
root.geometry("")
# BackEnd
class Backend():
def __init__(self):
self.conn = sqlite3.connect('accounting.db')
self.cur = self.conn.cursor()
self.conn.execute("""CREATE TABLE IF NOT EXISTS account_type(
id INTEGER PRIMARY KEY,
category_type INTEGER NOT NULL,
category_id TEXT NOT NULL
)"""),
self.conn.commit()
self.conn.close()
def insert_account_type(self, category_type, category_id):
self.conn = sqlite3.connect('accounting.db')
self.cur = self.conn.cursor()
self.cur.execute("""INSERT INTO account_type(category_id, category_type) VALUES(?,?);""",
(self,category_type, category_id,))
self.conn.commit()
self.conn.close()
def view_account_type(self):
self.conn = sqlite3.connect('accounting.db')
self.cur = self.conn.cursor()
self.cur.execute("SELECT * FROM account_type")
self.rows = self.cur.fetchall()
self.conn.close()
return self.rows
# calling the class
tb = Backend()
# Front End
class Frontend():
def __init__(self, master):
# Frames
self.top_frame = LabelFrame(master,bg ='SlateGrey', relief=SUNKEN)
self.top_frame.pack()
self.bottom_frame = LabelFrame(master, bg = 'SlateGrey', relief=SUNKEN)
self.bottom_frame.pack()
self.right_frame = LabelFrame(self.top_frame, bg = 'SlateGrey', relief = FLAT,
text = 'Details Entry',fg = 'maroon')
self.right_frame.pack(side = RIGHT, anchor = NE)
self.side_frame = LabelFrame(self.top_frame,bg ='SlateGrey',relief=SUNKEN,text = 'Menu Buttons',fg = 'maroon')
self.side_frame.pack(side = LEFT,anchor = NW)
self.bot_frame = LabelFrame(self.bottom_frame, bg='Grey',relief = SUNKEN,text = 'Field View',fg = 'maroon')
self.bot_frame.pack(side = BOTTOM,anchor = SW)
# Side Buttons
self.btn1 = Button(self.side_frame,
text='Main Account Types',
bg='SteelBlue4',
font=('cambria', 11),
anchor=W,
fg='white',
width=18,height=2,
command=lambda :[self.main_account()])
self.btn1.grid(row=0, column=0, pady=0, sticky=W)
def main_account(self):
# variables
self.category_type = StringVar()
self.category_id = StringVar()
# functions
def add_main_accounts():
if self.category_type.get() == "" or self.category_id.get() == "":
tkinter.messagebox.showinfo('All fields are required')
else:
Backend.insert_account_type(
self.category_type.get(),
self.category_id.get(),) # category type unfilled
tkinter.messagebox.showinfo('Entry successful')
def display_account_types(self):
self.trv.delete(*self.trv.get_children())
for self.rows in Backend.view_account_type(self):
self.trv.insert("", END, values=self.rows)
def get_account_type(e):
self.selected_row = self.trv.focus()
self.data = self.trv.item(self.selected_row)
global row
row = self.data["values"]
"""Grab items and send them to entry fields"""
self.category_id.set(row[1])
self.category_type.set(row[2])
"""=================TreeView==============="""
# Scrollbars
ttk.Style().configure("Treeview", background = "SlateGrey", foreground = "white", fieldbackground = "grey")
scroll_x = Scrollbar(self.bot_frame, orient = HORIZONTAL)
scroll_x.pack(side = BOTTOM, fill = X)
scroll_y = Scrollbar(self.bot_frame, orient = VERTICAL)
scroll_y.pack(side = RIGHT, fill = Y)
# Treeview columns & setting scrollbars
self.trv = ttk.Treeview(self.bot_frame, height=3, columns=
('id', 'category_id', 'category_type'), xscrollcommand = scroll_x.set, yscrollcommand = scroll_y.set)
# Treeview style configuration
ttk.Style().configure("Treeview", background = "SlateGrey", foreground = "white", fieldbackground = "grey")
# Configure vertical and Horizontal scroll
scroll_x.config(command = self.trv.xview)
scroll_y.config(command = self.trv.yview)
# Treeview Headings/columns
self.trv.heading('id', text = "No.")
self.trv.heading('category_id', text = 'Category ID')
self.trv.heading('category_type', text = 'Category Type')
self.trv['show'] = 'headings'
# Treeview columns width
self.trv.column('id', width = 23)
self.trv.column('category_id', width = 70)
self.trv.column('category_type', width = 100)
self.trv.pack(fill = BOTH, expand = YES)
# Binding Treeview with data
self.trv.bind('<ButtonRelease-1>',get_account_type)
# Account Types Labels
self.lbl1 = Label(self.right_frame,text = 'Category ID',anchor = W,
width=10,font = ('cambria',11,),bg = 'SlateGrey')
self.lbl1.grid(row = 0,column = 0,pady = 5)
self.lbl2 = Label(self.right_frame, text = 'Category Type', anchor = W,
width = 10,font = ('cambria',11,),bg = 'SlateGrey')
self.lbl2.grid(row = 1, column = 0,pady = 5,padx=5)
self.blank_label = Label(self.right_frame, bg='SlateGrey')
self.blank_label.grid(row=2, columnspan=2, pady=10)
# Account Type Entries
self.entry1 = Entry(self.right_frame,textvariable = self.category_id,
font = ('cambria',11,),bg = 'Grey',width=14)
self.entry1.grid(row = 0,column=1,sticky = W,padx = 5)
self.entry2 = Entry(self.right_frame, textvariable = self.category_type,
font = ('cambria', 11,), bg = 'Grey',width = 14)
self.entry2.grid(row = 1, column = 1, sticky = W,pady = 5,padx = 5)
# Buttons
self.btn_1 = Button(self.right_frame,text = 'Add',font = ('cambria',12,'bold'),bg = 'SlateGrey',
activebackground='green', fg = 'white',width=12,height = 2,relief=RIDGE,
command = lambda :[add_main_accounts()])
self.btn_1.grid(row = 3,column = 0,pady = 15)
self.btn_2 = Button(self.right_frame, text = 'View', font = ('cambria', 12, 'bold'),
bg = 'SlateGrey',command=lambda :[display_account_types()],
activebackground='green', fg ='white', width=12, height = 2, relief = RIDGE)
self.btn_2.grid(row = 3, column = 1)
# calling the class
app = Frontend(root)
root.mainloop()
I got and answer to this question,
I just passed in the 'self' argument to the inner nested functions of the class as below and it worked.
# functions
def add_main_accounts(self):
if self.category_id.get() == "" or self.category_type.get() == "":
tkinter.messagebox.showinfo('All fields are required')
else:
Backend.insert_account_type(self,
self.category_id.get(),
self.category_type.get()) # category type unfilled
tkinter.messagebox.showinfo('Entry successful')
def display_account_types(self):
self.trv.delete(*self.trv.get_children())
for rows in Backend.view_account_type(self):
self.trv.insert("", END, values = rows)
return
def get_account_type(e):
self.selected_row = self.trv.focus()
self.data = self.trv.item(self.selected_row)
global row
self.row = self.data["values"]
"""Grab items and send them to entry fields"""
self.category_id.set(row[1])
self.category_type.set(row[2])
I think you should remove the self in display_account_types function like you did to the previous one.

Take the last date range input in R Shiny

[I'm trying to quote the app user for multiple date range inputs. However, the number of date range inputs could be different every time. For example, this time I have 3 periods and next time I may have 17 periods to grab. How should I code the endDate to have R grab the last date range input automatically?]
1
ui <-fluidPage(
dateRangeInput('dateRange1', label = 'period1', start = '', end = '' ),
dateRangeInput('dateRange2', label = 'period2', start = '', end = '' ),
dateRangeInput('dateRange3', label = 'period3', start = '', end = '' ),
dateRangeInput('dateRange4', label = 'period4', start = '', end = '' ),
dateRangeInput('dateRange5', label = 'period5', start = '', end = '' ),
dateRangeInput('dateRange6', label = 'period6', start = '', end = '' ),
dateRangeInput('dateRange7', label = 'period7', start = '', end = '' ),
dateRangeInput('dateRange8', label = 'period8', start = '', end = '' ),
dateRangeInput('dateRange9', label = 'period9', start = '', end = '' ),
dateRangeInput('dateRange10', label = 'period10', start = '', end = '' ),
dateRangeInput('dateRange11', label = 'period11', start = '', end = '' ),
dateRangeInput('dateRange12', label = 'period12', start = '', end = '' ),
dateRangeInput('dateRange13', label = 'period13', start = '', end = '' ),
dateRangeInput('dateRange14', label = 'period14', start = '', end = '' ),
dateRangeInput('dateRange15', label = 'period15', start = '', end = '' ),
dateRangeInput('dateRange16', label = 'period16', start = '', end = '' ),
dateRangeInput('dateRange17', label = 'period17', start = '', end = '' ),
dateRangeInput('dateRange18', label = 'period18', start = '', end = '' ),
dateRangeInput('dateRange19', label = 'period19', start = '', end = '' ),
dateRangeInput('dateRange20', label = 'period20', start = '', end = '' ),
actionButton("submit", "Submit")
)
server <- function(input, output, session) {
observeEvent(input$submit, {
startDate = input$dateRange1[1]
endDate = ???
})
}
To save typing energy we can use a wrapper function when it makes sense.
dateRanger <- function(range, label, start, end) {
lst1 <- Map(dateRangeInput, range, label=label, start=start, end=end)
c(lst1, list(actionButton('submit', "Submit")))
}
dr <- dateRanger(paste0("dateRange", 1:20),
paste0("period", 1:20), '', '')
f2 <- do.call('fluidPage', unname(dr))
all.equal(f1, f2)
#[1] TRUE
You could get a list of all of the dateRangeXX inputs using
dateRanges <- grep('dateRange', names(input), value = T)
You would then extract the minimum and maximum values by converting the dateRange inputs into a matrix of dates and calculating the start and end dates.
dateMatrix <- sapply(dateRanges, function(x) {input[[x]]})
dateMin <- min(dateMatrix[ ,1], na.rm = T)
dateMax <- max(dateMatrix[ ,2], na.rm = T)

Update Shiny-R custom progressbar

I use to put some progressbar in my shiny apps using shinyBS package. But the new version working with bootstrap 3 does not have the option.
As shiny included progressbar is not customizable as wanted, I tried to remake the BS one compatible with bootstrap 3. It works well but I do not manage to update it.
Thanks in advance for any help about this!
Here is an exemple,
NB : label and size are not included in the js yet.
Server : (from https://gist.github.com/artemklevtsov/d280c4343b052c2aaaef )
server <- function(input, output,session) {
tags$script(src="ShinyProgress.js"),
progressBar <- function(inputId,value = 0, label = FALSE, color = "info", size = NULL,
striped = FALSE, active = FALSE, vertical = FALSE) {
if (!is.null(size))
size <- match.arg(size, c("sm", "xs", "xxs"))
text_value <- paste0(value, "%")
if (vertical)
style <- htmltools::css(height = text_value, `min-height` = "2em")
else
style <- htmltools::css(width = text_value, `min-width` = "2em")
htmltools::tags$div(
class = "progress",
id=inputId,
class = if (!is.null(size)) paste0("progress-", size),
class = if (vertical) "vertical",
class = if (active) "active",
htmltools::tags$div(
class = "progress-bar",
class = paste0("progress-bar-", color),
class = if (striped) "progress-bar-striped",
style = style,
role = "progressbar",
`aria-valuenow` = value,
`aria-valuemin` = 0,
`aria-valuemax` = 100,
htmltools::tags$span(class = if (!label) "sr-only", text_value)
)
)
}
updatePB=function(session,inputId,value=NULL,label=NULL,color=NULL,size=NULL,striped=NULL,active=NULL,vertical=NULL) {
data <- dropNulls(list(id=inputId,value=value,label=label,color=color,size=size,striped=striped,active=active,vertical=vertical))
session$sendCustomMessage("updateprogress", data)
}
dropNulls=function(x) {
x[!vapply(x,is.null,FUN.VALUE=logical(1))]
}
observe({input$n1 ; updatePB(session,inputId="pb1",value=input$n1)})
}
UI :
ui <- fluidPage(
numericInput(inputId="n1", label="numeric input", value=10, min = 0, max = 100, step = 1),
mainPanel(progressBar(inputId="pb1",value=10))
)
And I add the following js code to www (as ShinyProgress.js) :
Shiny.addCustomMessageHandler("updateprogress",
function(data) {
$el = $("#"+data.id);
if(data.hasOwnProperty('value')) {
$el.css('width', data.value+'%').attr('aria-valuenow', data.value);
};
if(data.hasOwnProperty('color')) {
$el.removeClass("progress-bar-standard progress-bar-info progress-bar-success progress-bar-danger progress-bar-warning");
$el.addClass("progress-bar-"+data.color);
};
if(data.hasOwnProperty('striped')) {
$el.toggleClass('progress-bar-striped', data.striped);
};
if(data.hasOwnProperty('active')) {
$el.toggleClass('active', data.active);
};
if(data.hasOwnProperty('vertical')) {
$el.toggleClass('vertical', data.vertical);
};
}
);
edit :
I am able to add some clarification, when js code is executed, aria-valuenow and width are well updated but in the main div so the modification is not taken into account :
<div aria-valuenow="100" style="width: 100%;" id="pb1">
<div aria-valuemax="100" aria-valuemin="0" aria-valuenow="0" class="progress-bar progress-bar-info" role="progressbar" style="width:0%;min-width:2em;">
<span class="sr-only">0%</span>
</div>
</div>
So the solution was quite easy, just change the level of the id in the function :
progressBar <- function(inputId, value=0, label=F, color="info", size=NULL, striped=F, active=F, vertical=F) {
stopifnot(is.numeric(value))
if (value < 0 || value > 100)
stop("'value' should be in the range from 0 to 100", call. = FALSE)
if (!(color %in% shinydashboard:::validColors || color %in% shinydashboard:::validStatuses))
stop("'color' should be a valid status or color.", call. = FALSE)
if (!is.null(size))
size <- match.arg(size, c("sm", "xs", "xxs"))
text_value <- paste0(value, "%")
if (vertical)
style <- htmltools::css(height = text_value, `min-height` = "2em")
else
style <- htmltools::css(width = text_value, `min-width` = "2em")
htmltools::tags$div(
class = "progress",
# id=inputId,
class = if (!is.null(size)) paste0("progress-", size),
class = if (vertical) "vertical",
class = if (active) "active",
htmltools::tags$div(
id=inputId,
class = "progress-bar",
class = paste0("progress-bar-", color),
class = if (striped) "progress-bar-striped",
style = style,
role = "progressbar",
`aria-valuenow` = value,
`aria-valuemin` = 0,
`aria-valuemax` = 100,
htmltools::tags$span(class = if (!label) "sr-only", text_value)
)
)
}
I hope that it will be helpfull for any shiny developper to add custom progressbar.

create multiple buttons from table in lua ( Corona sdk )

I have a table which looks like this:
table =
{
{
id = 1,
name = 'john',
png = 'john.png',
descr = "..."
},
{
id = 2,
name = 'sam',
png = "sam.png",
descr = "..."
}
...
}
What function could I use to display each picture like this and make them buttons
so that when I click on their image I can open their info.
This is where I am stuck:
local buttons = display.newGroup()
local xpos = -20
local ypos = 0
local e = -1
function addpicture ()
for i=1, #table do
xpos = (xpos + 100) % 300
e = e + 1
ypos = math.modf((e)*1/3) * 100 + 100
local c = display.newImage( table[i].name, system.TemporaryDirectory, xpos, ypos)
c:scale( 0.4, 0.4 )
c.name = table[i].tvname
buttons:insert(c)
end
end
function buttons:touch( event )
if event.phase == "began" then
print(self, event.id)
end
end
buttons:addEventListener('touch', buttons)
addpicture()
How can I recognize which image is touched in order to go back to the persons info?
I solved my problem by adding the listener inside of the loop like this:
function addpicture ()
for i=1, #table do
xpos = (xpos + 100) % 300
e = e + 1
ypos = math.modf((e)*1/3) * 100 + 100
local c = display.newImage( table[i].name, system.TemporaryDirectory, xpos, ypos)
c:scale( 0.4, 0.4 )
c.name = table[i].tvname
buttons:insert(c)
function c:touch( event )
if event.phase == "began" then
print(self, event.id)
end
end
c:addEventListener('touch', c)
end
end
addpicture()

Error: Attempt to index global 'fifteenButton' (a nil value)

Error Line: 92
Attempt to index global 'fifteenButton' (a nil value)
stack traceback:
[C]: ?
/Users/ejaytumacder/dev/HappyShaker/time_select.lua:92: in function </Users/ejaytumacder/dev/HappyShaker/time_select.lua:90>
?: in function 'dispatchEvent'
?: in function '?'
?: in function 'gotoScene'
/Users/ejaytumacder/dev/HappyShaker/time_select.lua:12: in function '_onRelease'
?: in function '?'
?: in function <?:406>
?: in function <?:218>
This is the error I get above, and below is the code that it originates from.
local storyboard = require("storyboard")
local widget = require("widget")
local scene = storyboard.newScene()
local mydata = require("mydata")
local function fifteenSecondButtonEvent( event )
local phase = event.phase
if "ended" == phase then
mydata.time = 15
storyboard.gotoScene("play")
end
end
local function thirtySecondButtonEvent( event )
local phase = event.phase
if "ended" == phase then
mydata.time = 30
storyboard.gotoScene("play")
end
end
local function sixtySecondButtonEvent( event )
local phase = event.phase
if "ended" == phase then
mydata.time = 60
storyboard.gotoScene("play")
end
end
function scene:createScene( event )
local group = self.view
local timeText = display.newText("TIME", 160, 70, "Helvetica", 30)
group:insert( timeText )
local fifteenButton = widget.newButton {
time = 15,
left = 75,
top = 150,
width = 164,
height = 42,
defaultFile = "fifteen_button.png",
overFile = "fifteen_button_pressed.png",
label = "",
onRelease = fifteenSecondButtonEvent
}
--group:insert(fifteenButton)
local thirtyButton = widget.newButton {
time = 30,
left = 75,
top = 250,
width = 164,
height = 42,
defaultFile = "thirty_button.png",
overFile = "thirty_button_pressed.png",
label = "",
onRelease = thirtySecondButtonEvent
}
--group:insert(thirtyButton)
local sixtyButton = widget.newButton {
time = 60,
left = 75,
top = 350,
width = 164,
height = 42,
defaultFile = "sixty_button.png",
overFile = "sixty_button_pressed.png",
label = "",
onRelease = sixtySecondButtonEvent
}
group:insert(fifteenButton)
group:insert(thirtyButton)
group:insert(sixtyButton)
print( "Number of children in Display Group: " .. group.numChildren )
end
function scene:willEnterScene( event )
local group = self.view
end
function scene:enterScene( event )
local group = self.view
end
function scene:exitScene( event )
local group = self.view
fifteenButton:removeEventListener( 'onRelease', fifteenSecondButtonEvent ) -- line 92
thirtyButton:removeEventListener( 'onRelease', thirtySecondButtonEvent )
sixtyButton:removeEventListener( 'onRelease', sixtySecondButtonEvent )
timeText:removeSelf()
timeText = nil
if fifteenButton then
fifteenButton:removeSelf()
fifteenButton = nil
end
if thirtyButton then
thirtyButton:removeSelf()
thirtyButton = nil
end
if sixtyButton then
sixtyButton:removeSelf()
sixtyButton = nil
end
display.remove(group)
storyboard.removeScene( "time_select" )
end
function scene:destroyScene( event )
local group = self.view
end
scene:addEventListener("createScene", scene)
scene:addEventListener("willEnterScene", scene)
scene:addEventListener("enterScene", scene)
scene:addEventListener("exitScene", scene)
scene:addEventListener("destroyScene", scene)
return scene
So your question has two problems going on. I'm going to address why you're getting that error.
You are getting that error on line 92 because you are defining fifteenButton in the createScene function. as a local object. So it can't be referenced outside the createScene function. To fix that issue you should add local fifteenButton, thirtyButton, sixtyButton to the top of the file. Then remove the local from before the same named variables in the createScene. This will fix your error.

Resources