Hi,
My code is as follows
local composer = require( "composer" ) local scene = composer.newScene() --------------------------------------------------------------------------------- -- All code outside of the listener functions will only be executed ONCE -- unless "composer.removeScene()" is called. --------------------------------------------------------------------------------- -- local forward references should go here --------------------------------------------------------------------------------- -- "scene:create()" function scene:create( event ) local sceneGroup = self.view self.\_background = display.newRect(self.view, display.contentWidth/2, display.contentHeight/2, display.contentWidth, display.contentHeight ) self.\_background.strokeWidth = 3 self.\_background:setFillColor(0, 0, 0 ) self.\_background.alpha = 0.5 self.playButton = display.newImageRect(self.view, "assets/common/play.jpg", 225, 225) self.playButton.x = display.contentWidth/2 self.playButton.y =display.contentHeight/2 self:AddEventListeners() --Add the touch listener -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. end function scene:TouchHandler() print("yay") end function scene:AddEventListeners() self.playButton = TouchHandler self.playButton:addEventListener("touch", self.playButton) end -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene
I am trying to add the event handler by calling
self:AddEventListeners()
which in turn should do the following
function scene:AddEventListeners() self.playButton = TouchHandler self.playButton:addEventListener("touch", self.playButton) end
but it says self.playButton is unknown… so how do I do it?
Thanks