Hi Brent and Rob: Thanks for the prompt feedback. Brent, sorry about the white box on the image, my mistake. What I meant to say was that if the user tapped the yellow “Name” button, it would trigger a popup text field box to enter a childs name. Peach Pellen helped me with that code a few years back, so it’s probably outdated! Here is what it looks like:
–NEW FILE FUNCTION
–This function is called when a user clicks on an empty file
local function newFile ()
--Creates a display group for popup images to be stored in for easy management
local popupGroup = display.newGroup()
--Mask the background with a semi transparent “layer”
local safeMask = display.newRect( 0, 0, 1024, 768 )
safeMask:setFillColor(0,0,0,180)
--Prevent event propogation (users can’t click buttons if popup is open)
local function blocker ()
return true
end
--We assign touch and tap listeners so neither touches or taps can propogate
safeMask:addEventListener(“tap”, blocker)
safeMask:addEventListener(“touch”, blocker)
--Popup box image
local popupBox = display.newRect( 300, 300, 424, 168 )
--When the user clicks “OK” save the new data, set their current level at 1
--and clean up the popup group before changing to the level select screen
local function submitPopup(event)
--Modified to prevent names over 15 characters in length
if event.phase == “editing” and string.len(nameBox.text) > 15 then
nameBox.text = nameBox.text:sub(1,15)
end
if event.phase == “submitted” then
saveValue(“file” …ID… “.data”, nameBox.text)
_G.username = nameBox.text
saveValue(""…_G.username…".data", 1)
saveValue(""…_G.username…“ID.data”, ID)
_G.currentLevel = 1
popupGroup:removeSelf()
popupGroup = nil
native.setKeyboardFocus(nil)
director:changeScene(“levels”)
end
end
--Text field for user to enter their name
--submitPopup is listened for when the user presses enter
nameBox = native.newTextField(320, 320, 384, 60, submitPopup)
nameBox.size = 24
--Place all objects in the group so they can be easily and effectively cleaned up
popupGroup:insert(safeMask)
popupGroup:insert(popupBox)
popupGroup:insert(nameBox)
end
–BUTTON FUNCTIONALITY (FOR FILE BUTTONS)
local function buttonHandler (event)
if event.phase == “release” then
--If empty call popup we coded above to create new file
if status[event.id] == “Name” then
ID = event.id
newFile()
else
--If not empty load the data and set the username and current level
--for later use
_G.username = files[event.id]
_G.currentLevel = loadValue(""…_G.username…".data")
director:changeScene(“levels”)
end
end
end
–BUTTONS FOR FILES
–[[
Each button (there are currently 5) are set up the exact same way. We’re currently using
the UI library for these buttons.
Default = normal image shown
Over = image shown when touch is down on the button
id = the file number
text = grab the status/name of the button and set it as text
textColor = color of text in r, g, b
size = font size
emboss = embossed true or false, true looks nicer normally
x = x coordinate for button
y = y coordinate for button
–]]
local button1 = ui.newButton{
default = “buttonYellow.png”,
over = “buttonYellowOver.png”,
id = 1,
onEvent = buttonHandler,
text = status[1],
textColor = {51, 51, 51, 255},
size = 22,
emboss = true,
x = 110,
y = 360
}
local button2 = ui.newButton{
default = “buttonYellow.png”,
over = “buttonYellowOver.png”,
id = 2,
onEvent = buttonHandler,
text = status[2],
textColor = {51, 51, 51, 255},
size = 22,
emboss = true,
x = 310,
y = 360
}
— etc…button fields go up to ten.
I tried to edit using Rob’s link for native.newTextField for both “Standard” and “Numeric”, but that didn’t fix it. Not sure what you mean Rob by deleting the call listener and creating a second one. Sorry for being so dense, I’m still a newbie as coding goes. If you can please take a look and suggest what section area I need to work on, I’ll keep plugging away at it. Thanks!
John (-