I used this code for displaying text using URL data and tried to add displayed text on slideview
local docname = {}
local dispname = “{”
local params = {}
params.progress = true
function networkListener1( event )
if ( event.isError ) then
print( “Network error - download failed” )
else
--print( “Response:”… event.response )
someTable = json.decode(event.response)
for i = 1, #someTable do
Doctor_Name = someTable[i].doctorName
docname = json.encode (Doctor_Name)
dispname = dispname … docname
if i ~= #someTable then
dispname = dispname … “,” – {“temp1.png”,
end
end
dispname = dispname … “}”
docname = dispname
print("doccccccc " … docname)
slideView.new( DoctorImage, docname)
end
end
network.request("https://app.ellorasystems.com/curie/doctor/getDetails/all/all/all
slideView.lua
– slideView.lua
module(…, package.seeall)
local screenW, screenH = display.contentWidth, display.contentHeight
local viewableScreenW, viewableScreenH = display.viewableContentWidth, display.viewableContentHeight
local screenOffsetW, screenOffsetH = display.contentWidth - display.viewableContentWidth, display.contentHeight - display.viewableContentHeight
local imgNum = nil
local images = nil
local text
local touchListener, nextImage, prevImage, cancelMove, initImage
local background
local imageNumberText, imageNumberTextShadow
function new( imageSet, textset, slideBackground, top, bottom )
local pad = 20
local top = top or 0
local bottom = bottom or 0
local g = display.newGroup()
if slideBackground then
background = display.newImage(slideBackground, 0, 0, true)
else
background = display.newRect( 0, 0, screenW, screenH-(top+bottom) )
– set anchors on the background
background.anchorX = 0
background.anchorY = 0
background:setFillColor(0, 0.77, 0.52)
end
g:insert(background)
images = {}
text = {}
for i = 1, #imageSet do
local p = display.newImage(imageSet[i])
print(“imagese[i]”, imageSet[i])
local t = display.newText(textset[i], 0, 0, native.systemFont, 20)
print(“textset[i]”, textset[i])
local h = viewableScreenH-(top+bottom)
if p.width > viewableScreenW or p.height > h then
if p.width/viewableScreenW > p.height/h then
p.xScale = viewableScreenW/p.width + pad
p.yScale = viewableScreenW/p.width
else
p.xScale = h/p.height
p.yScale = h/p.height
end
end
g:insert§
if t.width > viewableScreenW or t.height > h then
if t.width/viewableScreenW > t.height/h then
t.xScale = viewableScreenW/t.width + pad
t.yScale = viewableScreenW/t.width
else
t.xScale = h/t.height
t.yScale = h/t.height
end
end
g:insert(t)
if (i > 1) then
p.x = screenW*1.5 + pad
t.x = screenW*1.5 + pad – all images offscreen except the first one
else
p.x = screenW*.5
t.x = screenW*.5
end
p.y = h*.3
t.y = h*.5
images[i] = p
text[i] = t
end
local defaultString = "1 of " … #images
local navBar = display.newGroup()
g:insert(navBar)
local navBarGraphic = display.newImage(“navBar.png”, 0, 0, false)
navBar:insert(navBarGraphic)
navBarGraphic.x = viewableScreenW*.5
navBarGraphic.y = 0
imageNumberText = display.newText(defaultString, 0, 0, native.systemFontBold, 14)
imageNumberText:setFillColor(1, 1, 1)
imageNumberTextShadow = display.newText(defaultString, 0, 0, native.systemFontBold, 14)
imageNumberTextShadow:setFillColor(0, 0, 0)
navBar:insert(imageNumberTextShadow)
navBar:insert(imageNumberText)
imageNumberText.x = navBar.width*.5
imageNumberText.y = navBarGraphic.y
imageNumberTextShadow.x = imageNumberText.x - 1
imageNumberTextShadow.y = imageNumberText.y - 1
navBar.y = math.floor(navBar.height*0.5)
imgNum = 1
g.x = 0
g.y = top + display.screenOriginY
function touchListener (self, touch)
local phase = touch.phase
print(“slides”, phase)
if ( phase == “began” ) then
– Subsequent touch events will target button even if they are outside the contentBounds of button
display.getCurrentStage():setFocus( self )
self.isFocus = true
startPos = touch.x
prevPos = touch.x
transition.to( navBar, { time=200, alpha=math.abs(navBar.alpha-1) } )
elseif( self.isFocus ) then
if ( phase == “moved” ) then
transition.to(navBar, { time=400, alpha=0 } )
if tween then transition.cancel(tween) end
print(imgNum)
local delta = touch.x - prevPos
prevPos = touch.x
images[imgNum].x = images[imgNum].x + delta
text[imgNum].x = text[imgNum].x + delta
if (images[imgNum-1]) then
images[imgNum-1].x = images[imgNum-1].x + delta
end
if (images[imgNum+1]) then
images[imgNum+1].x = images[imgNum+1].x + delta
end
if (text[imgNum-1]) then
text[imgNum-1].x = text[imgNum-1].x + delta
end
if (text[imgNum+1]) then
text[imgNum+1].x = text[imgNum+1].x + delta
end
elseif ( phase == “ended” or phase == “cancelled” ) then
dragDistance = touch.x - startPos
print("dragDistance: " … dragDistance)
if (dragDistance < -40 and imgNum < #images and imgNum < #text) then
nextImage()
elseif (dragDistance > 40 and imgNum > 1) then
prevImage()
else
cancelMove()
end
if ( phase == “cancelled” ) then
cancelMove()
end
– Allow touch events to be sent normally to the objects they “hit”
display.getCurrentStage():setFocus( nil )
self.isFocus = false
end
end
return true
end
function setSlideNumber()
print(“setSlideNumber”, imgNum … " of " … #images)
imageNumberText.text = imgNum … " of " … #images
imageNumberTextShadow.text = imgNum … " of " … #images
end
function cancelTween()
if prevTween then
transition.cancel(prevTween)
end
prevTween = tween
end
function nextImage()
tween = transition.to( images[imgNum], {time=400, x=(screenW*.5 + pad)*-1, transition=easing.outExpo } )
tween = transition.to( images[imgNum+1], {time=400, x=screenW*.5, transition=easing.outExpo } )
tween = transition.to( text[imgNum], {time=400, x=(screenW*.5 + pad)*-1, transition=easing.outExpo } )
tween = transition.to( text[imgNum+1], {time=400, x=screenW*.5, transition=easing.outExpo } )
imgNum = imgNum + 1
initImage(imgNum)
end
function prevImage()
tween = transition.to( images[imgNum], {time=400, x=screenW*1.5+pad, transition=easing.outExpo } )
tween = transition.to( images[imgNum-1], {time=400, x=screenW*.5, transition=easing.outExpo } )
tween = transition.to( text[imgNum], {time=400, x=screenW*1.5+pad, transition=easing.outExpo } )
tween = transition.to( text[imgNum-1], {time=400, x=screenW*.5, transition=easing.outExpo } )
imgNum = imgNum - 1
initImage(imgNum)
end
function cancelMove()
tween = transition.to( images[imgNum], {time=400, x=screenW*.5, transition=easing.outExpo } )
tween = transition.to( images[imgNum-1], {time=400, x=(screenW*.5 + pad)*-1, transition=easing.outExpo } )
tween = transition.to( images[imgNum+1], {time=400, x=screenW*1.5+pad, transition=easing.outExpo } )
tween = transition.to( text[imgNum], {time=400, x=screenW*.5, transition=easing.outExpo } )
tween = transition.to( text[imgNum-1], {time=400, x=(screenW*.5 + pad)*-1, transition=easing.outExpo } )
tween = transition.to( text[imgNum+1], {time=400, x=screenW*1.5+pad, transition=easing.outExpo } )
end
function initImage(num)
if (num < #images) then
images[num+1].x = screenW*1.5 + pad
text[num+1].x = screenW*1.5 + pad
end
if (num > 1) then
images[num-1].x = (screenW*.5 + pad)*-1
text[num-1].x = (screenW*.5 + pad)*-1
end
– if (num < #text) then
– text[num+1].x = screenW*1.5 + pad
– end
– if (num > 1) then
– text[num-1].x = (screenW*.5 + pad)*-1
– end
setSlideNumber()
end
background.touch = touchListener
background:addEventListener( “touch”, background )
------------------------
– Define public methods
function g:jumpToImage(num)
local i, j
print(“jumpToImage”)
print("#images", #images)
for i = 1, #images do
if i < num then
images[i].x = -screenW*.5;
elseif i > num then
images[i].x = screenW*1.5 + pad
else
images[i].x = screenW*.5 - pad
end
end
print("#Text", #text)
for j = 1, #text do
if j < num then
text[j].x = -screenW*.5;
elseif j > num then
text[j].x = screenW*1.5 + pad
else
text[j].x = screenW*.5 - pad
end
end
imgNum = num
initImage(imgNum)
end
function g:cleanUp()
print(“slides cleanUp”)
background:removeEventListener(“touch”, touchListener)
end
return g
end
but error occurs like this
17:14:24.618 ERROR: Runtime error
17:14:24.618 C:\tools\Lua_Eclipse\workspace\CurieFind_Doctor\src\slideView.lua:38: bad argument #1 to ‘newText’ (string expected, got nil)
17:14:24.618 stack traceback:
17:14:24.618 [C]: ?
17:14:24.618 [C]: in function ‘newText’
17:14:24.618 C:\tools\Lua_Eclipse\workspace\CurieFind_Doctor\src\slideView.lua:38: in function ‘new’
17:14:24.618 C:\tools\Lua_Eclipse\workspace\CurieFind_Doctor\src\DoctorsDetails.lua:91: in function <C:\tools\Lua_Eclipse\workspace\CurieFind_Doctor\src\DoctorsDetails.lua:70>
how to solve this error?
pls help me anybody