**My dear friends,
I tried very hard to add scroll function in my storyboard, and now I can turn pages.
The only problem is my app still crashes sometimes. I am now pretty sure something wrong happened in my memory control. I was wondering if anyone here could kindly check the code for me, I have spent two days, and haven’t got any luck.
warm regards,
Henry
[code]local p01 = storyboard.newScene (“p01”)
function p01:createScene( event )
local localGroup = self.view
local scrollView = widget.newScrollView{
top = 0, left = 0,
width = display.contentWidth, height = display.contentHeight,
bgColor = { 255, 255, 255, 0 }, --Un-Comment this to set the background color of the scrollView.
– scrollBarColor = { 255, 0, 128 }, --Un-Comment this to set the scrollBar to a custom color.
– hideScrollBar = true, --Un-Comment this to hide the scrollBar
– listener = scrollListener
}
local lotsOfText = “\n\n\n\n\n\n\n\n\np01\n\n\n”
local lotsOfTextObject = display.newText(lotsOfText, 0, 0,display.contentWidth-100,0, “Helvetica”, 30, display.contentWidth*.05)
lotsOfTextObject:setTextColor( 0 )
lotsOfTextObject:setReferencePoint( display.TopCenterReferencePoint )
lotsOfTextObject.x = display.contentCenterX
lotsOfTextObject.y = 0
localGroup:insert(lotsOfTextObject)
scrollView:insert(lotsOfTextObject)
local background = display.newRect(localGroup,0, 0, display.contentWidth, display.contentHeight)
background:setFillColor(255, 255, 255)
localGroup:insert(scrollView)
local backbutton = display.newImage (“Graphics/backbutton.png”)
backbutton.x = 390
backbutton.y = 1150
localGroup:insert(backbutton)
local function pressBack (event)
–if event.phase == “ended” then
require (“toc”)
storyboard.gotoScene( “toc” )
storyboard.removeScene( “p01” )
if (scrollView) then
scrollView:removeSelf()
scrollView = nil
end
– end
end
backbutton:addEventListener (“tap”, pressBack)
local narrator = display.newImage (“Graphics/audio.png”)
narrator.x = 520
narrator.y = 1000
localGroup:insert(narrator)
–>This places the "narrator"button
local stop = display.newImage (“Graphics/stop.png”)
stop.x = 290
stop.y = 1000
localGroup:insert(stop)
–> This places the “stop” button
audio01 = audio.loadStream(“Audio/1.mp3”)
function narrator:tap(event)
audio.play(audio01)
end
function stop: tap(event)
audio.stop()
end
narrator:addEventListener (“tap”, narrator)
stop: addEventListener (“tap”, stop)
backbutton:addEventListener (“tap”, stop)
local nextpagebutton = display.newImage (“Graphics/nextpage.png”)
nextpagebutton.x = 620
nextpagebutton.y = 1150
localGroup:insert(nextpagebutton)
local function pressNextpagebutton (event)
– if event.phase == “ended” then
require (“p02”)
storyboard.gotoScene (“p02”)
storyboard.removeScene( “p01” )
if (scrollView) then
scrollView:removeSelf()
scrollView = nil
end
– end
end
nextpagebutton:addEventListener (“tap”, pressNextpagebutton)
nextpagebutton:addEventListener (“tap”, stop)
local previouspagebutton = display.newImage (“Graphics/previouspage.png”)
previouspagebutton.x = 170
previouspagebutton.y = 1150
localGroup:insert(previouspagebutton)
local function pressPreviouspagebutton (event)
– if event.phase == “ended” then
require (“toc”)
storyboard.gotoScene (“toc”)
storyboard.removeScene( “p01” )
if (scrollView) then
scrollView:removeSelf()
scrollView = nil
end
– end
end
previouspagebutton:addEventListener (“tap”, pressPreviouspagebutton)
previouspagebutton:addEventListener (“tap”, stop)
local switchbutton = display.newImage (“Graphics/switch.png”)
switchbutton.x = 170
switchbutton.y = 10000
localGroup:insert(switchbutton)
local function pressSwitchbutton (event)
– if event.phase == “ended” then
require (“p01t”)
storyboard.gotoScene (“p01t”)
storyboard.removeScene( “p01” )
if (scrollView) then
scrollView:removeSelf()
scrollView = nil
end
– end
end
switchbutton:addEventListener (“tap”, pressSwitchbutton)
switchbutton:addEventListener (“tap”, stop)
local title = display.newImage (“Graphics/title2.png”, true, “zoomEven”)
title.x = 390;
title.y = 135;
localGroup:insert(title)
return p01;
end
function p01:enterScene( event )
local group = self.view
– INSERT code here (e.g. start timers, load audio, start listeners, etc.)
end
– Called when scene is about to move offscreen:
function p01:exitScene( event )
local group = self.view
– INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)
end
– If scene’s view is removed, scene:destroyScene() will be called just prior to:
function p01:destroyScene( event )
local group = self.view
print(“scene p01 destroyed”)
p01 = nil
audio.dispose(audio01)
audio01 = nil
end
– END OF YOUR IMPLEMENTATION
– “createScene” event is dispatched if scene’s view does not exist
p01:addEventListener( “createScene”, p01 )
– “enterScene” event is dispatched whenever scene transition has finished
p01:addEventListener( “enterScene”, p01 )
– “exitScene” event is dispatched whenever before next scene’s transition begins
p01:addEventListener( “exitScene”, p01 )
– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
p01:addEventListener( “destroyScene”, p01 )[code]
[import]uid: 150748 topic_id: 33560 reply_id: 333560[/import]**