hi, i actually have inserted everything into the function scene:createScene.
here’s the code:
local storyboard = require "storyboard" local scene = storyboard.newScene() local widget = require( "widget" ) function scene:createScene (event) local screenGroup = self.view local function scrollListener( event ) local phase = event.phase local direction = event.direction if "began" == phase then --print( "Began" ) elseif "moved" == phase then --print( "Moved" ) elseif "ended" == phase then --print( "Ended" ) end -- If the scrollView has reached it's scroll limit if event.limitReached then if "up" == direction then print( "Reached Top Limit" ) elseif "down" == direction then print( "Reached Bottom Limit" ) elseif "left" == direction then print( "Reached Left Limit" ) elseif "right" == direction then print( "Reached Right Limit" ) end end return true end -- Create a ScrollView local scrollView = widget.newScrollView { left = 0, top = 0, width = display.contentWidth, height = display.contentHeight, bottomPadding = 50, id = "onBottom", horizontalScrollDisabled = true, verticalScrollDisabled = false, listener = scrollListener, } local background = display.newImageRect( "world.jpg", 500, 500) background.x = display.contentCenterX background.y = display.contentCenterY scrollView:insert ( background ) local imageMegaman = display.newImageRect ( "megaman.jpg", 250, 200) imageMegaman.x = display.contentCenterX imageMegaman.y = 400 -- insert scrollView to imageMegaman scrollView:insert ( imageMegaman ) local textObject2 = display.newText ( "Hello Scene 2!", display.contentCenterX, 30, native.systemFont, 18) textObject2:setFillColor ( 255, 0, 0) --Create a text object for the scrollViews title local titleText = display.newText("Move Up to Scroll", display.contentCenterX, 48, native.systemFontBold, 16) titleText:setFillColor( 0 ) -- insert the text object into the created display group scrollView:insert( titleText ) local lotsOfText = "bla bla ijgijroigjre goirejgregregre. ijroi vhreiubvhre biurehbiure goiu regre., Curabitur imperdiet consectetur euismod. Phasellus non ipsum vel eros vestibulum consequat. Integer convallis quam id urna tristique eu viverra risus eleifend.\n\nAenean suscipit placerat venenatis. Pellentesque faucibus venenatis eleifend. Nam lorem felis, rhoncus vel rutrum quis, tincidunt in sapien. Proin eu elit tortor. Nam ut mauris pellentesque justo vulputate convallis eu vitae metus. Praesent mauris eros, hendrerit ac convallis vel, cursus quis sem. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque fermentum, dui in vehicula dapibus, lorem nisi placerat turpis, quis gravida elit lectus eget nibh. Mauris molestie auctor facilisis.\n\nCurabitur lorem mi, molestie eget tincidunt quis, blandit a libero. Cras a lorem sed purus gravida rhoncus. Cras vel risus dolor, at accumsan nisi. Morbi sit amet sem purus, ut tempor mauris.\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur imperdiet consectetur euismod. Phasellus non ipsum vel eros vestibulum consequat. Integer convallis quam id urna tristique eu viverra risus eleifend.\n\nAenean suscipit placerat venenatis. Pellentesque faucibus venenatis eleifend. Nam lorem felis, rhoncus vel rutrum quis, tincidunt in sapien. Proin eu elit tortor. Nam ut mauris pellentesque justo vulputate convallis eu vitae metus. Praesent mauris eros, hendrerit ac convallis vel, cursus quis sem. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque fermentum, dui in vehicula dapibus, lorem nisi placerat turpis, quis gravida elit lectus eget nibh. Mauris molestie auctor facilisis.\n\nCurabitur lorem mi, molestie eget tincidunt quis, blandit a libero. Cras a lorem sed purus gravida rhoncus. Cras vel risus dolor, at accumsan nisi. Morbi sit amet sem purus, ut tempor mauris. " local textObject = display.newText( lotsOfText, display.contentCenterX, 0, 300, 0, "Helvetica", 18) textObject:setFillColor ( 255, 0, 0) textObject.anchorY = 0.0 -- buat bikin text nya ini jadi ke tengah2 atas bawahnya textObject.y = titleText.y + titleText.contentHeight + 10 scrollView:insert( textObject ) local function myTouchListener( event ) if ( event.phase == "began" ) then --code executed when the button is touched print( "kepencet si objectnya di scene 2" ) storyboard.gotoScene( "scene2kescene1") return true end end textObject:addEventListener( "touch" , myTouchListener ) local function fromScene2ToScene2 () storyboard.gotoScene( "scene2" ) end local function fromScene2ToScene1 () print "pindah scene sukses ke loading tea dari 2" storyboard.gotoScene("scene2kescene1") return true end local tabButtons = { { width = 32, height = 32, defaultFile = "assets/tabIcon.png", overFile = "assets/tabIcon-down.png", label = "Screen 1", onPress = fromScene2ToScene1, selected = true }, { width = 32, height = 32, defaultFile = "assets/tabIcon.png", overFile = "assets/tabIcon-down.png", label = "Screen 2", onPress = fromScene2ToScene2, selected = true }, { width = 32, height = 32, defaultFile = "assets/tabIcon.png", overFile = "assets/tabIcon-down.png", label = "Screen 3", onPress = fromScene2ToScene2, selected = true } } -- Create the widget local demoTabs = widget.newTabBar { top = display.contentHeight - 7, width = display.contentWidth, backgroundFile = "assets/tabbar.png", tabSelectedLeftFile = "assets/tabBar\_tabSelectedLeft.png", tabSelectedMiddleFile = "assets/tabBar\_tabSelectedMiddle.png", tabSelectedRightFile = "assets/tabBar\_tabSelectedRight.png", tabSelectedFrameWidth = 20, tabSelectedFrameHeight = 52, buttons = tabButtons } print "createScene sukses" end function scene:enterScene( event ) local group = self.view print "enterScene event berhasil" end function scene:exitScene( event ) local group = self.view end function scene:destroyScene( event ) local group = self.view print( "destroying scene 2" ) end scene:addEventListener( "createScene", scene ) 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
basically i already posted everything inside the createScene function. not sure if i should have moved the “listeners” to outside the createScene but i didn’t encounter any problem from scene1 to scene2 with everything inside the createScene, why in scene2 to scene 1, there’s problem? (and btw after the scene 2 to scene 1 problem, if i click the button to go back to scene 2 again, it’s still like that, everything on top of each other)