android - (Corona SDK) Properly remove a scrollView -


in game have scrollview widget declared inside function, , want remove scrollview using function, this:

local function createscrollview(event) if(event.phase=="ended")then     local function scrolllistener( event )         local phase = event.phase         local direction = event.direction          if "began" == phase             --print( "began" )         elseif "moved" == phase             print( "moved" )         elseif "ended" == phase             --print( "ended" )         end          -- if scrollview has reached it's scroll limit         if event.limitreached             if "up" == direction                 print( "reached top limit" )             elseif "down" == direction                 print( "reached bottom limit" )             elseif "left" == direction                 print( "reached left limit" )             elseif "right" == direction                 print( "reached right limit" )             end             end             return true         end          -- create scrollview         local scrollview = widget.newscrollview         {             left = display.contentwidth/2-130,             top = display.contentheight/2-165,             width = 440,             height = 300,             bottompadding = 10,             id = "onbottom",             backgroundcolor = { 0, 0, 0, 0 },             horizontalscrolldisabled = true,             verticalscrolldisabled = false,             listener = scrolllistener,         }     end end local function removescrollview(event)     if(event.phase==ended)then         if scrollview             scrollview:removeself()             scrollview = nil         end     end end 

it doesn't return error, can see scrollview still exists because corona terminal keeps printing "moved".

do know how remove it?

thank you.

local scrollview ------------edited  local function createscrollview(event)  if(event.phase=="ended")then    local function scrolllistener( event )      local phase = event.phase      local direction = event.direction      if "began" == phase         --print( "began" )     elseif "moved" == phase         print( "moved" )     elseif "ended" == phase         --print( "ended" )     end      -- if scrollview has reached it's scroll limit     if event.limitreached         if "up" == direction             print( "reached top limit" )         elseif "down" == direction             print( "reached bottom limit" )         elseif "left" == direction             print( "reached left limit" )         elseif "right" == direction             print( "reached right limit" )         end         end         return true     end      -- create scrollview     ---edited---------------------    scrollview = widget.newscrollview     {         left = display.contentwidth/2-130,         top = display.contentheight/2-165,         width = 440,         height = 300,         bottompadding = 10,         id = "onbottom",         backgroundcolor = { 0, 0, 0, 0 },         horizontalscrolldisabled = true,         verticalscrolldisabled = false,         listener = scrolllistener,     }  end end  local function removescrollview(event)  if(event.phase==ended)then     if scrollview         scrollview:removeself()         scrollview = nil     end  end end 

so can remove scroll view in removescrollview function.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -