Touch event with scrollView

Hi,

I have added a scrollView to my app similar to the code below which is from the documentation here. I read somewhere on how to add a touch event in the scrollView control so it only fires when you are not scrolling. Does anyone know how to do this? I added a separate listener to the scrollView and check for the x/y to see if they touched in a certain area. But I can’t scroll now. How can I get for x/y touches in the scrollView (it contains one image) and have the scrolling? Is there a special event.type I use for this?

Thanks!

Warren

local widget = require "widget"  
  
-- function to listen to scrollView events  
local function scrollViewListener( event )  
 local s = event.target -- reference to scrollView object  
  
 if event.type == "beganScroll" then  
 print( "beganScroll event type" )  
  
 elseif event.type == "endedScroll" then  
 print( "endedScroll event type" )  
  
 elseif event.type == "movingToTopLimit" then  
 print( "movingToTopLimit event type" )  
  
 elseif event.type == "movingToBottomLimit" then  
 print( "movingToBottomLimit event type" )  
  
 elseif event.type == "movingToLeftLimit" then  
 print( "movingToLeftLimit event type" )  
  
 elseif event.type == "movingToRightLimit" then  
 print( "movingToRightLimit event type" )  
 end  
end  
  
-- Create a new ScrollView widget:  
local scrollView = widget.newScrollView{  
 width = 320  
 height = 320,  
 scrollWidth = 768,  
 scrollHeight = 1024,  
 maskFile="mask-320x320.png",  
 listener = scrollViewListener  
}  
  
-- Create an object and place it inside of ScrollView:  
local myObject = display.newImage( "myobj.png" )  
scrollView:insert( myObject )  
  
-- Place the ScrollView into a group:  
local someGroup = display.newGroup()  
someGroup:insert( scrollView )  
  
-- Remove the ScrollView (will also remove content inserted into, e.g. myObject):  
display.remove( scrollView )  
scrollView = nil  

[import]uid: 184193 topic_id: 34809 reply_id: 334809[/import]

I think what you want is to add a touch event to an object that’s in your scrollView. By default if you touch/drag a scrollView it will scroll without you doing anything else. But if you have something in the scrollView that needs to be touched, then the scrollView won’t scroll because that object took the touch event.

In that case, you basically need to have the object detect if the touch is moving and if it is, forward the touch event to the scrollView.

I think you want something like this:

local function someTouchHandler(event)  
 if event.phase == "ended" then  
 -- do what you want for the touch  
 elseif event.phase == "moved" then -- Check if you moved your finger while touching  
 local dx = math.abs( event.x - event.xStart ) -- Get the x-transition of the touch-input  
 local dy = math.abs( event.y - event.yStart ) -- Get the y-transition of the touch-input  
 if dx \> 5 or dy \> 5 then  
 scrollView:takeFocus( event ) -- If the x- or y-transition is more than 5 put the focus to your scrollview  
 end  
 end  
 return true  
end  

[import]uid: 199310 topic_id: 34809 reply_id: 138405[/import]

Hi,

Thanks for your help. I had tried that before and can’t get it to work right. So I added your code in again and commented in there when the prints happen for debugging. I can tell I am clicking on the image I am scrolling but none of the other parts of the event work. Do you see anything obvious? With this in there it will not scroll or do anything.

Thanks,

Warren

----------------------------------------------------------------------------------  
--  
-- SceneEvents.lua  
--  
----------------------------------------------------------------------------------  
  
local storyboard = require( "storyboard" )  
local scene = storyboard.newScene()  
local widget = require "widget"  
local imgHeader  
  
 local scrollView = widget.newScrollView{  
 width = 320,  
 height = 424,  
 top = 0,  
 left = 0,  
 scrollWidth = 320,  
 scrollHeight = 700,  
 maskFile="mask\_home.png",  
 listener = scrollViewListener,  
 }  
local function someTouchHandler(event)  
 print ("0") --This does happen   
 if event.phase == "ended" then  
 print ("1") --Never happens  
 -- do what you want for the touch  
 elseif event.phase == "moved" then -- Check if you moved your finger while touching  
 print("2") --Never happens  
 local dx = math.abs( event.x - event.xStart ) -- Get the x-transition of the touch-input  
 local dy = math.abs( event.y - event.yStart ) -- Get the y-transition of the touch-input  
 if dx \> 5 or dy \> 5 then  
 print ("3") --Never happens  
 scrollView:takeFocus( event ) -- If the x- or y-transition is more than 5 put the focus to your scrollview  
 end  
 end  
 return true  
end  
  
-- function to listen to scrollView events  
local function scrollViewListener( event )  
 local s = event.target -- reference to scrollView object  
  
 if event.type == "beganScroll" then  
 print( "beganScroll event type" )  
  
 elseif event.type == "endedScroll" then  
 print( "endedScroll event type" )  
  
 elseif event.type == "movingToTopLimit" then  
 print( "movingToTopLimit event type" )  
  
 elseif event.type == "movingToBottomLimit" then  
 print( "movingToBottomLimit event type" )  
  
 elseif event.type == "movingToLeftLimit" then  
 print( "movingToLeftLimit event type" )  
  
 elseif event.type == "movingToRightLimit" then  
 print( "movingToRightLimit event type" )  
 end  
end  
  
---------------------------------------------------------------------------------  
-- BEGINNING OF YOUR IMPLEMENTATION  
---------------------------------------------------------------------------------  
  
-- Called when the scene's view does not exist:  
function scene:createScene( event )  
 local screenGroup = self.view  
 imgHeader = display.newImage( "screen\_main.png" )  
 scrollView:insert(imgHeader)   
 imgHeader.touch = someTouchHandler  
 imgHeader:addEventListener("touch", imgHeader) -- [!] added due to flag code  
 imgBarHome = display.newImage( "bar\_home.png",0,425)  
 screenGroup:insert(imgBarHome)   
end  
  
-- Called immediately after scene has moved onscreen:  
function scene:enterScene( event )  
  
 imgHeader.ready = true -- [!] flag method  
  
 --[[[!] disabled due to flag method  
 -- Update Lua memory text display  
 local showMem = function()  
 imgHeader:addEventListener( "touch", imgHeader )  
 end  
 local memTimer = timer.performWithDelay( 1000, showMem, 1 )  
 --]]  
end  
-- Called when scene is about to move offscreen:  
function scene:exitScene( event )  
 local group = self.view  
  
 imgHeader.ready = false -- [!] flag method  
  
 --imgHeader:removeEventListener( "touch", imgHeader ) -- [!] disabled due to flag method  
  
end  
-- Called prior to the removal of scene's "view" (display group)  
function scene:destroyScene( event )  
 local group = self.view  
  
end  
---------------------------------------------------------------------------------  
-- END OF YOUR IMPLEMENTATION  
---------------------------------------------------------------------------------  
  
-- "createScene" event is dispatched if scene's view does not exist  
scene:addEventListener( "createScene", scene )  
  
-- "enterScene" event is dispatched whenever scene transition has finished  
scene:addEventListener( "enterScene", scene )  
  
-- "exitScene" event is dispatched before next scene's transition begins  
scene:addEventListener( "exitScene", scene )  
  
-- "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().  
scene:addEventListener( "destroyScene", scene )  
  
---------------------------------------------------------------------------------  
  
return scene  

[import]uid: 184193 topic_id: 34809 reply_id: 138462[/import]

I think the problem is because you’re creating the scrollView and telling it the name of the handler before the handler is defined, which is passing a “nil” in meaning no handler.

Move the widget.newScrollView() call inside of your scene’s createScene() function. You should do this anyway because if the scene gets purged and it comes back, only code in the storyboard functions gets reexecuted. The content at the top is only initialized on the very first load.
[import]uid: 199310 topic_id: 34809 reply_id: 138517[/import]

Thanks. I did this and then ran it. It still does not scroll. And when i try I am getting the 0 printed but nothing else. It’s like it is not recognizing then event.phase as ended or moved because it never gets in there.

Warren
[import]uid: 184193 topic_id: 34809 reply_id: 138519[/import]

Anyone have an idea on this? I’m stuck on the project till I can get past this.

The touch event is firing because it prints the 0 but does not enter any other of the event phases in the event.

Thanks,

Warren
[import]uid: 184193 topic_id: 34809 reply_id: 138712[/import]

I think you need to do this:

local function someTouchHandler(self, event)  

When you do a touch handler by passing the object to addEventListener(), then the first parameter that really gets passed is the object itself and the event table becomes the 2nd parameters.

I personally prefer to do functions and leave the object out of it. If it were me, I would leave someTouchHandler alone and change this:

 imgHeader.touch = someTouchHandler  
 imgHeader:addEventListener("touch", imgHeader) -- [!] added due to flag code  

to this

 imgHeader:addEventListener("touch", someTouchHandler) -- [!] added due to flag code  

event.target will be the object touched, so there really isn’t a lot of motivation to pass the object in twice, though the way you did it is technically more object oriented.

[import]uid: 199310 topic_id: 34809 reply_id: 138726[/import]

I did this and now when I try to scroll I get the following runtime error:

attempt to index local ‘event’ (a nil value)
This happens on the following line in the someTouchHandler:

 if event.phase == "ended" then  

[import]uid: 184193 topic_id: 34809 reply_id: 138790[/import]

Okay, I realized I needed to change this some to where I add controls right on the scene and image rather than use buttons drawn on the background image. So I commented out the event for the image and added a button. The button worked fine and the page scrolled like I wanted. Then I added an event for the button and when I click on it the color changes to the pressed color and stays like that. I can still scroll but the event that prints the button has been pressed never fired. Below is the code for the entire scene. Am I doing something wrong?

Thanks!!!

----------------------------------------------------------------------------------  
--  
-- SceneEvents.lua  
--  
----------------------------------------------------------------------------------  
  
local storyboard = require( "storyboard" )  
local scene = storyboard.newScene()  
local widget = require "widget"  
local imgHeader  
local onbtnHomeEvent = function (event )  
 if event.phase == "release" then  
 print( "You pressed and released a button!" )  
 end  
end  
  
local function someTouchHandler(self, event)  
 print ("0") --This does happen   
 if event.phase == "ended" then  
 print ("1") --Never happens  
 -- do what you want for the touch  
 elseif event.phase == "moved" then -- Check if you moved your finger while touching  
 print("2") --Never happens  
 local dx = math.abs( event.x - event.xStart ) -- Get the x-transition of the touch-input  
 local dy = math.abs( event.y - event.yStart ) -- Get the y-transition of the touch-input  
 if dx \> 5 or dy \> 5 then  
 print ("3") --Never happens  
 scrollView:takeFocus( event ) -- If the x- or y-transition is more than 5 put the focus to your scrollview  
 end  
 end  
 return true  
end  
  
-- function to listen to scrollView events  
local function scrollViewListener( event )  
 local s = event.target -- reference to scrollView object  
  
 if event.type == "beganScroll" then  
 print( "beganScroll event type" )  
  
 elseif event.type == "endedScroll" then  
 print( "endedScroll event type" )  
  
 elseif event.type == "movingToTopLimit" then  
 print( "movingToTopLimit event type" )  
  
 elseif event.type == "movingToBottomLimit" then  
 print( "movingToBottomLimit event type" )  
  
 elseif event.type == "movingToLeftLimit" then  
 print( "movingToLeftLimit event type" )  
  
 elseif event.type == "movingToRightLimit" then  
 print( "movingToRightLimit event type" )  
 end  
end  
  
---------------------------------------------------------------------------------  
-- BEGINNING OF YOUR IMPLEMENTATION  
---------------------------------------------------------------------------------  
  
-- Called when the scene's view does not exist:  
function scene:createScene( event )  
  
 local scrollView = widget.newScrollView{  
 width = 320,  
 height = 424,  
 top = 0,  
 left = 0,  
 scrollWidth = 320,  
 scrollHeight = 700,  
 maskFile="mask\_home.png",  
 listener = scrollViewListener,  
 }  
 local screenGroup = self.view  
 imgHeader = display.newImage( "screen\_main.png" )  
 scrollView:insert(imgHeader)   
 --imgHeader.touch = someTouchHandler  
 --imgHeader:addEventListener("touch", imgHeader) -- [!] added due to flag code  
 --imgHeader:addEventListener("touch", someTouchHandler)  
  
local btnHome = widget.newButton{  
 label = "Home",  
 font = "Arial",  
 fontSize = 14,  
 height=28,  
 width=80,  
 labelColor = { default={ 0 }, over={ 0 } },  
 defaultColor = { 206, 231, 231, 255 },  
 strokeColor = { 206, 231, 231, 255 },  
 onEvent = onbtnHomeEvent  
}  
 scrollView:insert(btnHome)   
btnHome.x = 53  
btnHome.y = 90  
 scrollView:insert(btnHome)   
  
 imgBarHome = display.newImage( "bar\_home.png",0,425)  
 screenGroup:insert(imgBarHome)   
  
end  
  
-- Called immediately after scene has moved onscreen:  
function scene:enterScene( event )  
  
 imgHeader.ready = true -- [!] flag method  
  
 --[[[!] disabled due to flag method  
 -- Update Lua memory text display  
 local showMem = function()  
 imgHeader:addEventListener( "touch", imgHeader )  
 end  
 local memTimer = timer.performWithDelay( 1000, showMem, 1 )  
 --]]  
end  
-- Called when scene is about to move offscreen:  
function scene:exitScene( event )  
 local group = self.view  
  
 imgHeader.ready = false -- [!] flag method  
  
 --imgHeader:removeEventListener( "touch", imgHeader ) -- [!] disabled due to flag method  
  
end  
-- Called prior to the removal of scene's "view" (display group)  
function scene:destroyScene( event )  
 local group = self.view  
  
end  
---------------------------------------------------------------------------------  
-- END OF YOUR IMPLEMENTATION  
---------------------------------------------------------------------------------  
  
-- "createScene" event is dispatched if scene's view does not exist  
scene:addEventListener( "createScene", scene )  
  
-- "enterScene" event is dispatched whenever scene transition has finished  
scene:addEventListener( "enterScene", scene )  
  
-- "exitScene" event is dispatched before next scene's transition begins  
scene:addEventListener( "exitScene", scene )  
  
-- "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().  
scene:addEventListener( "destroyScene", scene )  
  
---------------------------------------------------------------------------------  
return scene  

[import]uid: 184193 topic_id: 34809 reply_id: 138796[/import]

Hi @warrenwsav,
So if I read this code properly, you’re attempting to add a widget button inside a widget scrollview, and the button isn’t functioning properly? If so, this is a limitation of the current scrollview, but it will be solved in the upcoming revamped widget library, which is right around the corner (as in, really soon).

Thanks for your patience, let me know if your issue is otherwise than what I describe here.
Brent [import]uid: 200026 topic_id: 34809 reply_id: 138824[/import]

Thanks! At least I know it’s not my code - that is, if I’m doing it properly.

Do you think it will be a week or two when released?

Also, will I be able to add checkboxes and radio buttons inside the control also with the fix? I thinki those are the same widget if I’m not mistaken.

[import]uid: 184193 topic_id: 34809 reply_id: 138825[/import]

Hi again,
Yep, your estimated time is correct. Should be soon; documentation is being complied and final testing is underway.

Also, yes, you will be able to add checkboxes and radio buttons inside. :slight_smile:

Brent [import]uid: 200026 topic_id: 34809 reply_id: 138828[/import]

I think what you want is to add a touch event to an object that’s in your scrollView. By default if you touch/drag a scrollView it will scroll without you doing anything else. But if you have something in the scrollView that needs to be touched, then the scrollView won’t scroll because that object took the touch event.

In that case, you basically need to have the object detect if the touch is moving and if it is, forward the touch event to the scrollView.

I think you want something like this:

local function someTouchHandler(event)  
 if event.phase == "ended" then  
 -- do what you want for the touch  
 elseif event.phase == "moved" then -- Check if you moved your finger while touching  
 local dx = math.abs( event.x - event.xStart ) -- Get the x-transition of the touch-input  
 local dy = math.abs( event.y - event.yStart ) -- Get the y-transition of the touch-input  
 if dx \> 5 or dy \> 5 then  
 scrollView:takeFocus( event ) -- If the x- or y-transition is more than 5 put the focus to your scrollview  
 end  
 end  
 return true  
end  

[import]uid: 199310 topic_id: 34809 reply_id: 138405[/import]

Hi,

Thanks for your help. I had tried that before and can’t get it to work right. So I added your code in again and commented in there when the prints happen for debugging. I can tell I am clicking on the image I am scrolling but none of the other parts of the event work. Do you see anything obvious? With this in there it will not scroll or do anything.

Thanks,

Warren

----------------------------------------------------------------------------------  
--  
-- SceneEvents.lua  
--  
----------------------------------------------------------------------------------  
  
local storyboard = require( "storyboard" )  
local scene = storyboard.newScene()  
local widget = require "widget"  
local imgHeader  
  
 local scrollView = widget.newScrollView{  
 width = 320,  
 height = 424,  
 top = 0,  
 left = 0,  
 scrollWidth = 320,  
 scrollHeight = 700,  
 maskFile="mask\_home.png",  
 listener = scrollViewListener,  
 }  
local function someTouchHandler(event)  
 print ("0") --This does happen   
 if event.phase == "ended" then  
 print ("1") --Never happens  
 -- do what you want for the touch  
 elseif event.phase == "moved" then -- Check if you moved your finger while touching  
 print("2") --Never happens  
 local dx = math.abs( event.x - event.xStart ) -- Get the x-transition of the touch-input  
 local dy = math.abs( event.y - event.yStart ) -- Get the y-transition of the touch-input  
 if dx \> 5 or dy \> 5 then  
 print ("3") --Never happens  
 scrollView:takeFocus( event ) -- If the x- or y-transition is more than 5 put the focus to your scrollview  
 end  
 end  
 return true  
end  
  
-- function to listen to scrollView events  
local function scrollViewListener( event )  
 local s = event.target -- reference to scrollView object  
  
 if event.type == "beganScroll" then  
 print( "beganScroll event type" )  
  
 elseif event.type == "endedScroll" then  
 print( "endedScroll event type" )  
  
 elseif event.type == "movingToTopLimit" then  
 print( "movingToTopLimit event type" )  
  
 elseif event.type == "movingToBottomLimit" then  
 print( "movingToBottomLimit event type" )  
  
 elseif event.type == "movingToLeftLimit" then  
 print( "movingToLeftLimit event type" )  
  
 elseif event.type == "movingToRightLimit" then  
 print( "movingToRightLimit event type" )  
 end  
end  
  
---------------------------------------------------------------------------------  
-- BEGINNING OF YOUR IMPLEMENTATION  
---------------------------------------------------------------------------------  
  
-- Called when the scene's view does not exist:  
function scene:createScene( event )  
 local screenGroup = self.view  
 imgHeader = display.newImage( "screen\_main.png" )  
 scrollView:insert(imgHeader)   
 imgHeader.touch = someTouchHandler  
 imgHeader:addEventListener("touch", imgHeader) -- [!] added due to flag code  
 imgBarHome = display.newImage( "bar\_home.png",0,425)  
 screenGroup:insert(imgBarHome)   
end  
  
-- Called immediately after scene has moved onscreen:  
function scene:enterScene( event )  
  
 imgHeader.ready = true -- [!] flag method  
  
 --[[[!] disabled due to flag method  
 -- Update Lua memory text display  
 local showMem = function()  
 imgHeader:addEventListener( "touch", imgHeader )  
 end  
 local memTimer = timer.performWithDelay( 1000, showMem, 1 )  
 --]]  
end  
-- Called when scene is about to move offscreen:  
function scene:exitScene( event )  
 local group = self.view  
  
 imgHeader.ready = false -- [!] flag method  
  
 --imgHeader:removeEventListener( "touch", imgHeader ) -- [!] disabled due to flag method  
  
end  
-- Called prior to the removal of scene's "view" (display group)  
function scene:destroyScene( event )  
 local group = self.view  
  
end  
---------------------------------------------------------------------------------  
-- END OF YOUR IMPLEMENTATION  
---------------------------------------------------------------------------------  
  
-- "createScene" event is dispatched if scene's view does not exist  
scene:addEventListener( "createScene", scene )  
  
-- "enterScene" event is dispatched whenever scene transition has finished  
scene:addEventListener( "enterScene", scene )  
  
-- "exitScene" event is dispatched before next scene's transition begins  
scene:addEventListener( "exitScene", scene )  
  
-- "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().  
scene:addEventListener( "destroyScene", scene )  
  
---------------------------------------------------------------------------------  
  
return scene  

[import]uid: 184193 topic_id: 34809 reply_id: 138462[/import]

I think the problem is because you’re creating the scrollView and telling it the name of the handler before the handler is defined, which is passing a “nil” in meaning no handler.

Move the widget.newScrollView() call inside of your scene’s createScene() function. You should do this anyway because if the scene gets purged and it comes back, only code in the storyboard functions gets reexecuted. The content at the top is only initialized on the very first load.
[import]uid: 199310 topic_id: 34809 reply_id: 138517[/import]

Thanks. I did this and then ran it. It still does not scroll. And when i try I am getting the 0 printed but nothing else. It’s like it is not recognizing then event.phase as ended or moved because it never gets in there.

Warren
[import]uid: 184193 topic_id: 34809 reply_id: 138519[/import]

Anyone have an idea on this? I’m stuck on the project till I can get past this.

The touch event is firing because it prints the 0 but does not enter any other of the event phases in the event.

Thanks,

Warren
[import]uid: 184193 topic_id: 34809 reply_id: 138712[/import]

I think you need to do this:

local function someTouchHandler(self, event)  

When you do a touch handler by passing the object to addEventListener(), then the first parameter that really gets passed is the object itself and the event table becomes the 2nd parameters.

I personally prefer to do functions and leave the object out of it. If it were me, I would leave someTouchHandler alone and change this:

 imgHeader.touch = someTouchHandler  
 imgHeader:addEventListener("touch", imgHeader) -- [!] added due to flag code  

to this

 imgHeader:addEventListener("touch", someTouchHandler) -- [!] added due to flag code  

event.target will be the object touched, so there really isn’t a lot of motivation to pass the object in twice, though the way you did it is technically more object oriented.

[import]uid: 199310 topic_id: 34809 reply_id: 138726[/import]

I did this and now when I try to scroll I get the following runtime error:

attempt to index local ‘event’ (a nil value)
This happens on the following line in the someTouchHandler:

 if event.phase == "ended" then  

[import]uid: 184193 topic_id: 34809 reply_id: 138790[/import]

Okay, I realized I needed to change this some to where I add controls right on the scene and image rather than use buttons drawn on the background image. So I commented out the event for the image and added a button. The button worked fine and the page scrolled like I wanted. Then I added an event for the button and when I click on it the color changes to the pressed color and stays like that. I can still scroll but the event that prints the button has been pressed never fired. Below is the code for the entire scene. Am I doing something wrong?

Thanks!!!

----------------------------------------------------------------------------------  
--  
-- SceneEvents.lua  
--  
----------------------------------------------------------------------------------  
  
local storyboard = require( "storyboard" )  
local scene = storyboard.newScene()  
local widget = require "widget"  
local imgHeader  
local onbtnHomeEvent = function (event )  
 if event.phase == "release" then  
 print( "You pressed and released a button!" )  
 end  
end  
  
local function someTouchHandler(self, event)  
 print ("0") --This does happen   
 if event.phase == "ended" then  
 print ("1") --Never happens  
 -- do what you want for the touch  
 elseif event.phase == "moved" then -- Check if you moved your finger while touching  
 print("2") --Never happens  
 local dx = math.abs( event.x - event.xStart ) -- Get the x-transition of the touch-input  
 local dy = math.abs( event.y - event.yStart ) -- Get the y-transition of the touch-input  
 if dx \> 5 or dy \> 5 then  
 print ("3") --Never happens  
 scrollView:takeFocus( event ) -- If the x- or y-transition is more than 5 put the focus to your scrollview  
 end  
 end  
 return true  
end  
  
-- function to listen to scrollView events  
local function scrollViewListener( event )  
 local s = event.target -- reference to scrollView object  
  
 if event.type == "beganScroll" then  
 print( "beganScroll event type" )  
  
 elseif event.type == "endedScroll" then  
 print( "endedScroll event type" )  
  
 elseif event.type == "movingToTopLimit" then  
 print( "movingToTopLimit event type" )  
  
 elseif event.type == "movingToBottomLimit" then  
 print( "movingToBottomLimit event type" )  
  
 elseif event.type == "movingToLeftLimit" then  
 print( "movingToLeftLimit event type" )  
  
 elseif event.type == "movingToRightLimit" then  
 print( "movingToRightLimit event type" )  
 end  
end  
  
---------------------------------------------------------------------------------  
-- BEGINNING OF YOUR IMPLEMENTATION  
---------------------------------------------------------------------------------  
  
-- Called when the scene's view does not exist:  
function scene:createScene( event )  
  
 local scrollView = widget.newScrollView{  
 width = 320,  
 height = 424,  
 top = 0,  
 left = 0,  
 scrollWidth = 320,  
 scrollHeight = 700,  
 maskFile="mask\_home.png",  
 listener = scrollViewListener,  
 }  
 local screenGroup = self.view  
 imgHeader = display.newImage( "screen\_main.png" )  
 scrollView:insert(imgHeader)   
 --imgHeader.touch = someTouchHandler  
 --imgHeader:addEventListener("touch", imgHeader) -- [!] added due to flag code  
 --imgHeader:addEventListener("touch", someTouchHandler)  
  
local btnHome = widget.newButton{  
 label = "Home",  
 font = "Arial",  
 fontSize = 14,  
 height=28,  
 width=80,  
 labelColor = { default={ 0 }, over={ 0 } },  
 defaultColor = { 206, 231, 231, 255 },  
 strokeColor = { 206, 231, 231, 255 },  
 onEvent = onbtnHomeEvent  
}  
 scrollView:insert(btnHome)   
btnHome.x = 53  
btnHome.y = 90  
 scrollView:insert(btnHome)   
  
 imgBarHome = display.newImage( "bar\_home.png",0,425)  
 screenGroup:insert(imgBarHome)   
  
end  
  
-- Called immediately after scene has moved onscreen:  
function scene:enterScene( event )  
  
 imgHeader.ready = true -- [!] flag method  
  
 --[[[!] disabled due to flag method  
 -- Update Lua memory text display  
 local showMem = function()  
 imgHeader:addEventListener( "touch", imgHeader )  
 end  
 local memTimer = timer.performWithDelay( 1000, showMem, 1 )  
 --]]  
end  
-- Called when scene is about to move offscreen:  
function scene:exitScene( event )  
 local group = self.view  
  
 imgHeader.ready = false -- [!] flag method  
  
 --imgHeader:removeEventListener( "touch", imgHeader ) -- [!] disabled due to flag method  
  
end  
-- Called prior to the removal of scene's "view" (display group)  
function scene:destroyScene( event )  
 local group = self.view  
  
end  
---------------------------------------------------------------------------------  
-- END OF YOUR IMPLEMENTATION  
---------------------------------------------------------------------------------  
  
-- "createScene" event is dispatched if scene's view does not exist  
scene:addEventListener( "createScene", scene )  
  
-- "enterScene" event is dispatched whenever scene transition has finished  
scene:addEventListener( "enterScene", scene )  
  
-- "exitScene" event is dispatched before next scene's transition begins  
scene:addEventListener( "exitScene", scene )  
  
-- "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().  
scene:addEventListener( "destroyScene", scene )  
  
---------------------------------------------------------------------------------  
return scene  

[import]uid: 184193 topic_id: 34809 reply_id: 138796[/import]